aboutsummaryrefslogtreecommitdiff
path: root/hw3/Lorenz.jl
diff options
context:
space:
mode:
authorsotech117 <michael_foiani@brown.edu>2024-02-21 00:48:31 -0500
committersotech117 <michael_foiani@brown.edu>2024-02-21 00:48:31 -0500
commit80ef2a117a0bca5bb6dbf025660d6c924f815d54 (patch)
treef06601272aae3605f23c64da9e1fedc7b173f17d /hw3/Lorenz.jl
parent0ba76d58cada341e6d570c5cb0ca0c19505e2607 (diff)
pull files from canvas to build off on
Diffstat (limited to 'hw3/Lorenz.jl')
-rw-r--r--hw3/Lorenz.jl32
1 files changed, 32 insertions, 0 deletions
diff --git a/hw3/Lorenz.jl b/hw3/Lorenz.jl
new file mode 100644
index 0000000..0144c92
--- /dev/null
+++ b/hw3/Lorenz.jl
@@ -0,0 +1,32 @@
+using DifferentialEquations
+using Plots
+
+# Simulate Lorenz 63 system and investigate sensitivity to initial conditions
+
+function tendency!(du, u, p, t)
+ x,y,z = u
+ σ,ρ,β = p
+
+ du[1] = dx = σ*(y-x)
+ du[2] = dy = x*(ρ-z) - y
+ du[3] = dz = x*y - β*z
+end
+
+p = [10.0, 28.0, 8/3] # parameters of the Lorentz 63 system
+tspan = (0.0, 1000.0)
+
+u0 = [1.0, 0.0, 0.0]
+δu0 = [0.0, 0.001, 0.0] # small deviation in initial condition
+
+prob = ODEProblem(tendency!, u0, tspan, p)
+sol1 = solve(prob, Tsit5(), reltol=1e-8, abstol=1e-8) # control simulation
+
+
+prob = ODEProblem(tendency!, u0 + δu0, tspan, p)
+sol2 = solve(prob, Tsit5(), reltol=1e-8, abstol=1e-8) # perturbed initial condition
+
+plot(sol1, idxs = (1, 2, 3)) # 3d plot
+
+# plot(sol1, idxs = (1, 2))
+
+plot([sol1[1, :], sol2[1, :]], [sol1[2, :], sol2[2, :]]) \ No newline at end of file