Skip to content

Quantitative Project on Computer Algebra using Python

Notifications You must be signed in to change notification settings

RyanGreenup/Python-Quant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Quant Project Python

* Slides

Emailed Problems

Exam Questions

A Problems

B Matrix Determinant Problem

Persian Recursion

Textbook Problems

Project A

Inter-Chapter

Chapter 3

Chapter 4

  • Problem 4.1

Notes

Resources

  • Rowland Prime Sequences (PDF)

Julia Plotting Libraries

  • Plotting
    • GadFly
    • GR
    • Python Plots
    • PlotlyJS
  • Visualisation
    • Makie
  • Drawing
    • Luxor
      • Turtles

Fractal Dimensions

Working-Explanation Not all fractals are self-similar (3B1B) but many processes that involve repetition lead to self similarity and the emergence of order and fractals.

Fractals model nature in a way that captures roughness, sort of the opposite of calculus in a way, but self-similarity is only a subset of all possible fractals.

Definition of Fractal

The definition of fractals has to do with fractal dimension, there is a way to define dimension so that fractals can be attributed a dimension.

The fractal dimension refers to the rate of change in measure of a shape in response to scaling.

So for example halving:

  • a line will reduce the length (i.e. measure) by half
  • a square will reduce the area (i.e. measure) by $\frac{1}{22}$
  • a cube will reduce the area (i.e. measure) by $\frac{1}{23}$

A natural question might be, how much will the area of any given fractal change? this value will be referred to as the fractal dimension.

When a shape is scaled by some ratio $s$ the change in measure / mass ($m$) will depend on the dimension $d$:

$$ m = sd $$

e.g. in the case of halving a cube the $m=\frac{1}{2}3$

How to solve the dimension

\[ D = logs\left( m \right) \]

So the dimension is non-integer, alghough many fractals can be depicted in 1/2/3 dimensions, the mass is also not quite an analogue because: length = ∞, area = 0

The dimension is easy to solve in self similar fractals because the measure is always known (e.g. when a sierpinski triangle is halved the the measure is reduced to a third and a Koch snowflake to a fourth)

So if we wanted to deal with non-self similar shapes, this concept of mass or measure, needs to be fleshed out.

For our approach we will generate our fractals on matrices and any non-zero element of the matrix will be considered as one unit of measure.

So by doing a log transform and linear regression we can find the dimension of any fractal shape, so, for example, a coast line.

Definition of a fractal

A fractal is any shape that has a non-integer dimension, which is essentially saying that the shape has complexity at all scales.

In a pure math sense the limit of the $d$ value as the scale zooms in and in, i.e. it has to continue to have complex curves (i.e. being rough).

In an applied setting it’s just that the dimension value has to stay constant accross a sufficiently wide range of scaling factors.

for example the dimension of Great Britain remains as about 1.21 through 1000X scale.

Well probably do another country, Aus/NZ umm Greenland maybe?

Build the Dragon

#------------------------------------------------------------
#--- Dragon -------------------------------------------------
#------------------------------------------------------------
function dragon(🐒, order, length)
    print(" ") # Don't remove this or code breaks, I don't know why?
    Turn(🐒, order*45)
    dragon_iterate(🐒, order, length, 1)
end
function dragon_iterate(🐒, order, length, sign)
    if order==0
        Forward(🐒, length)
    else
        rootHalf = sqrt(0.5)
        dragon_iterate(🐒, order -1, length*rootHalf, 1)
        Turn(🐒, sign * -90)
        dragon_iterate(🐒, order -1, length*rootHalf, -1)
    end
end
;mkdir /tmp/dragon
@png begin
    🐒 = Turtle()
    Turn(🐒, 180)
    Penup(🐒)
    Forward(🐒, 200)
    Pendown(🐒)
    Turn(🐒, 180)
    dragon(🐒, 15, 400)
end 1000 1000

for i in 1:20
    name = string("/tmp/dragon/", lpad(i, 5, "0"), ".png")
    print(name)
    Drawing(600, 600, name)
    origin()
    background("white")
    sethue("black")
    ###
    🐒 = Turtle()
    Turn(🐒, 180)
    Penup(🐒)
    Forward(🐒, 200)
    Pendown(🐒)
    Turn(🐒, 180)
    dragon(🐒, i, 400)
    ###
    finish()
end
;montage -geometry 1200x1200 /tmp/dragon/*.png /tmp/dragon/dragon.png

Report

Outline

Directory Structure

tree ./
./
β”œβ”€β”€ Problems
β”‚Β Β  β”œβ”€β”€ 00EmailedInitialProblems
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ Matrix-Determinant.ipynb
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ Matrix-Determinant-Numpy.ipynb
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ partA.py
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ Persian-Recursion
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ Persian-Recursion-Example.R
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ Persian-Recursion.ipynb
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ Persian-Recursion.py
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ Persian-Recursion.R
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── test2.py
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ proba2.py
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ ProbA.md
β”‚Β Β  β”‚Β Β  └── ProbA.pdf
β”‚Β Β  β”œβ”€β”€ chapter_03
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ prob31-recursive-fraction.ipynb
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ Problem 3.2.md
β”‚Β Β  β”‚Β Β  └── Problem 3.6.md
β”‚Β Β  β”œβ”€β”€ chapter_04
β”‚Β Β  β”œβ”€β”€ Docs
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ Lists
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── Python-Lists.ipynb
β”‚Β Β  β”‚Β Β  └── Variable-Scope-of-Nested-Functions.md
β”‚Β Β  β”œβ”€β”€ Julia
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ PlotlyAttempt.ipynb
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ primes.jl
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ surfaceiplot.png
β”‚Β Β  β”‚Β Β  └── Symata-FoldList.ipynb
β”‚Β Β  β”œβ”€β”€ Learning-Sympy
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ FindPrimes.ipynb
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ _minted-input
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ sympyDocs.py
β”‚Β Β  β”‚Β Β  └── Sympy.ipynb
β”‚Β Β  β”œβ”€β”€ Matrix-Exponentiation
β”‚Β Β  β”‚Β Β  └── Matrix-Exponentiation.ipynb
β”‚Β Β  └── ProjectA
β”‚Β Β      β”œβ”€β”€ A-12(1).py
β”‚Β Β      β”œβ”€β”€ A-12.ipynb
β”‚Β Β      β”œβ”€β”€ A-12.jl
β”‚Β Β      β”œβ”€β”€ A-35.py
β”‚Β Β      β”œβ”€β”€ A-44.ipynb
β”‚Β Β      β”œβ”€β”€ A-44.pdf
β”‚Β Β      β”œβ”€β”€ a44SurdSeries.html
β”‚Β Β      β”œβ”€β”€ a44SurdSeries.pdf
β”‚Β Β      β”œβ”€β”€ Recursion.md
β”‚Β Β      └── Recursion.pdf
β”œβ”€β”€ README.org
β”œβ”€β”€ Report
β”‚Β Β  β”œβ”€β”€ pythonQuant.bbl
β”‚Β Β  β”œβ”€β”€ pythonQuant.org
β”‚Β Β  β”œβ”€β”€ pythonQuant.pdf
β”‚Β Β  β”œβ”€β”€ pythonQuant.synctex.gz
β”‚Β Β  β”œβ”€β”€ pythonQuant.tex
β”‚Β Β  └── references.bib
└── Resources
    β”œβ”€β”€ 9780495708247.pdf (1231)
    β”‚Β Β  β”œβ”€β”€ 9780495708247.pdf - Differential equations.pdf
    β”‚Β Β  β”œβ”€β”€ cover.jpg
    β”‚Β Β  └── metadata.opf
    β”œβ”€β”€ (Graduate Texts in Mathematics 222) Brian Hall (auth.) - Lie Groups, Lie Algebras, and Representations_ An Elementary Introduction-Springer International Publishing (2015).pdf
    β”œβ”€β”€ references.bib
    β”œβ”€β”€ style.sty
    └── turing.pdf

15 directories, 48 files

Dot Graph

So I was going to turn this into a dot graph but I gave up.

But the point was going to be to illustrate that It’d be nice if we symlinked problems out of Project A into Ch. 3/4/5 etc.

  @startuml
digraph finite_state_machine {
    rankdir=LR;
    size="8,5"

    node [shape = doublecircle,  label = "Problems" ]; pb;
    node [shape = doublecircle,  label = "Resources" ]; rs;
    node [shape = square,  label = "00EmaiiledInitialProblems" ]; eml;
    node [shape = square,  label = "Docs" ]; d;
    node [shape = oval,  label = "Ch. 3" ]; c3;
    node [shape = oval,  label = "Ch. 4" ]; c4;
    node [shape = oval,  label = "Ch. 5" ]; c5;
    node [shape = circle,  label = "Julia" ]; jl;
    node [shape = circle,  label = "Learning-Sympy" ]; sp;
    node [shape = circle,  label = "ProjectA" ]; pa;
    node [shape = circle,  label = "README.org" ]; rd;
    node [shape = circle,  label = "Report" ]; rp;

    node [shape = circle];
    pb -> eml [];
    pb -> c3 [];
    pb -> c4 [];
    pb -> c5 [];
    pb -> d [];
    pb -> jl [];
    pb -> sp [];
    pb -> rp [];
    pb -> rd [];
    pb -> pa [];
    pb -> rs [];
    rs -> docs [];
    pa -> c3 [];
    pa -> c4 [];
    c4 -> eml [];
}
@enduml

dir-tree-puml.png

About

Quantitative Project on Computer Algebra using Python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published