{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "using DifferentialEquations" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "bluesky (generic function with 1 method)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "μ = 0.456\n", "ϵ = 0.0357\n", "\n", "function bluesky(du,u,p,t)\n", " du[1] = u[1]*(2+μ-10(u[1]^2+u[2]^2)) + u[3]^2 + u[2]^2+2u[2]\n", " du[2] = -u[3]^3-(1+u[2])*(u[3]^2+u[2]^2+2u[2])-4*u[1]+μ*u[2]\n", " du[3] = (1+u[2])*u[3]^2+u[1]^2-ϵ\n", "end" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "retcode: Success\n", "Interpolation: specialized 4th order \"free\" interpolation\n", "t: 533-element Array{Float64,1}:\n", " 0.0 \n", " 0.000242794\n", " 0.00267074 \n", " 0.0091564 \n", " 0.0196942 \n", " 0.034228 \n", " 0.0547106 \n", " 0.0828306 \n", " 0.121833 \n", " 0.175646 \n", " 0.250851 \n", " 0.361763 \n", " 0.480232 \n", " ⋮ \n", " 97.327 \n", " 97.5545 \n", " 97.755 \n", " 97.9734 \n", " 98.1957 \n", " 98.4781 \n", " 98.7962 \n", " 99.0634 \n", " 99.3472 \n", " 99.6414 \n", " 99.9307 \n", " 100.0 \n", "u: 533-element Array{Array{Float64,1},1}:\n", " [1.0, 0.0, 0.0] \n", " [0.998174, -0.000970108, 0.000233683]\n", " [0.980537, -0.0105562, 0.00252316] \n", " [0.938275, -0.0352128, 0.00825583] \n", " [0.881238, -0.0727312, 0.0165861] \n", " [0.818717, -0.120308, 0.0265473] \n", " [0.750202, -0.181046, 0.0384] \n", " [0.677017, -0.255469, 0.0517152] \n", " [0.595216, -0.346082, 0.0661592] \n", " [0.497891, -0.453002, 0.0804787] \n", " [0.371867, -0.573941, 0.0923551] \n", " [0.198736, -0.698181, 0.0979653] \n", " [0.0462886, -0.7658, 0.095936] \n", " ⋮ \n", " [-0.340419, 0.171288, -0.0124758] \n", " [-0.264768, 0.314069, 0.00164854] \n", " [-0.155254, 0.314244, 0.00354042] \n", " [-0.045482, 0.246791, -0.00189027] \n", " [0.0546987, 0.145436, -0.00962507] \n", " [0.166218, -0.0172594, -0.0157618] \n", " [0.212106, -0.229048, -0.0142034] \n", " [0.133021, -0.364671, -0.0147955] \n", " [-0.0280167, -0.369638, -0.0233519] \n", " [-0.225648, -0.160061, -0.0281007] \n", " [-0.340265, 0.175505, -0.0116722] \n", " [-0.329319, 0.236798, -0.00631381] " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "u0 = [1.0;0.0;0.0]\n", "tspan = (0.0,100.0)\n", "prob = ODEProblem(bluesky,u0,tspan)\n", "sol = solve(prob)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "using Plots\n", "plot(sol,vars=(1,2,3))" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\u001b[1m\u001b[36mINFO: \u001b[39m\u001b[22m\u001b[36mSaved animation to /Users/noriakioshita/Github/julia/ml_page/julia/tmp.gif\n", "\u001b[39m" ] }, { "data": { "text/html": [ "\" />" ], "text/plain": [ "Plots.AnimatedGif(\"/Users/noriakioshita/Github/julia/ml_page/julia/tmp.gif\")" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plt = path3d(1, xlim=(-3,3), ylim=(-3,3), zlim=(-3,3),\n", " xlab = \"x\", ylab = \"y\", zlab = \"z\",\n", " title = \"Gavrilov-A. Shilnikov model\", marker = 1)\n", "\n", "# build an animated gif, saving every 10th frame\n", "@gif for i=1:length(sol)\n", " push!(plt, sol[i][1], sol[i][2], sol[i][3])\n", "end every 3" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "displayfile (generic function with 1 method)" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "function displayfile(mimetype, filename)\n", " open(filename) do f\n", " base64text = base64encode(f)\n", " display(\"text/html\", \"\"\"\"\"\")\n", " end\n", "end" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "displayfile(\"image/gif\",\"./bluesky.gif\")" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "# ちょっと遅くしたもの\n", "displayfile(\"image/gif\",\"./bluesky2.gif\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "jupyter notebook で実行するとぐりぐり出来る" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " \n" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plotly()\n", "plot(sol[1,:],sol[2,:],sol[3,:], size=(500, 500))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Julia 0.6.2", "language": "julia", "name": "julia-0.6" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "0.6.2" } }, "nbformat": 4, "nbformat_minor": 2 }