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