using DifferentialEquations
INFO: Precompiling module DifferentialEquations.
f(u,p,t) = 1.01*u
u0=1/2
tspan = (0.0,1.0)
prob = ODEProblem(f,u0,tspan)
sol = solve(prob,Tsit5(),reltol=1e-8,abstol=1e-8)
using Plots
plot(sol,linewidth=5,title="Solution to the linear ODE with a thick line",
xaxis="Time (t)",yaxis="u(t) (in μm)",label="My Thick Line!") # legend=false
plot!(sol.t, t->0.5*exp(1.01t),lw=3,ls=:dash,label="True Solution!")
function lorenz(du, u, p, t)
du[1] = 10.0*(u[2]-u[1])
du[2] = u[1]*(20.7-u[3]) - u[2]
du[3] = u[1]*u[2] - (8/3)*u[3]
end
lorenz (generic function with 1 method)
# 初期値
u0 = [10.0;10.0;10.0]
tspan = (0.0, 1010.0)
prob = ODEProblem(lorenz,u0, tspan)
sol = solve(prob)
retcode: Success Interpolation: specialized 4th order "free" interpolation t: 4635-element Array{Float64,1}: 0.0 0.0410098 0.0724631 0.12384 0.17141 0.226671 0.280748 0.337579 0.396912 0.457744 0.519415 0.584054 0.652724 ⋮ 1007.52 1007.74 1007.98 1008.2 1008.43 1008.67 1008.89 1009.12 1009.37 1009.59 1009.82 1010.0 u: 4635-element Array{Array{Float64,1},1}: [10.0, 10.0, 10.0] [10.6287, 13.2749, 13.6552] [11.5663, 14.667, 17.2707] [12.8001, 13.9955, 23.6994] [12.5412, 10.1595, 27.8799] [10.2445, 4.7613, 28.4391] [7.11632, 1.46081, 25.9098] [4.31642, 0.254009, 22.4871] [2.45876, 0.191347, 19.2268] [1.49717, 0.498999, 16.3823] [1.13535, 0.890754, 13.9477] [1.14364, 1.38327, 11.8143] [1.45577, 2.12931, 9.97844] ⋮ [-7.33515, -7.27946, 19.8773] [-7.15645, -7.10882, 19.6712] [-7.24779, -7.34234, 19.5577] [-7.34667, -7.30934, 19.8626] [-7.16855, -7.10577, 19.7057] [-7.23337, -7.32828, 19.5418] [-7.35292, -7.33033, 19.8476] [-7.17841, -7.10549, 19.7306] [-7.22056, -7.31481, 19.5293] [-7.35645, -7.34579, 19.8338] [-7.18717, -7.10655, 19.751] [-7.15969, -7.21488, 19.5218]
plot(sol, vars=(1,2,3))
plot(sol,vars=(0,2))
f(x) = x^2-C*x+y^2
f (generic function with 3 methods)
#C=3.2 # 任意定数
#y = 1
#p1 = plot(size=(500, 500), legend=false, ylim=(-10,10))
#plot!(p1, f, -10, 10, lw=2.5)
plot(f)
g(x) = (C*exp(2x)-1)/(C*exp(2x)+1)
g (generic function with 2 methods)
plot(g)
y = 1
A = [1/e^2,1/e,1,e,e^2]
p1 = []
p2= plot(size=(500, 500),legend=false, ylim=(-5,5),xlim=(-5,5))
for i in 1:5
C = A[i]
push!(p1,g)
C = -A[i]
push!(p1,g)
end
#plot!(p2,p1[1])
#plot!(p2,p1[2])
#plot!(p2,p1[3])
#plot!(p2,p1[4])
#plot!(p1[5])
plot!(p2,p1[])
C = 1/e^2
plot!(g)
C = -1/e^2
plot!(p2,g)
C = 1/e
plot!(p2,g)
C = -1/e
plot!(p2,g)
C = 1
plot!(p2,g)
C = -1
plot!(p2,g)
C = e
plot!(p2,g)
C = -e
plot!(p2,g)
C = e^2
plot!(p2,g)
C = -e^2
plot!(p2,g)