In [10]:
using Plots; plotly(size=(200,200)); plot(Plots.fakedata(5,10)); # fully load plots
; # hide output
In [30]:
# Define the ODE for a simulation of Hooke's law.
k = 0.5
s = [0; 1.0]
f = (t,y) -> [0 1.0; -k 0.0]*y

# Do the simulation!
h = 0.01
Tmax = 100
tsteps = collect(0:h:Tmax)
nsteps = length(tsteps)
y = s
yhist = zeros(nsteps,2)
yhist[1,:] = s
for i=2:nsteps
    t = tsteps[i]
    y = y + h*f(t,y)
    yhist[i,:] = y
end
plot(tsteps,yhist[:,1])
Out[30]:
In [ ]:
# How should we debug?
In [12]:
Pkg.add("ODE")
INFO: Cloning cache of ODE from git://github.com/JuliaDiffEq/ODE.jl.git
INFO: Cloning cache of Polynomials from git://github.com/Keno/Polynomials.jl.git
INFO: Installing ODE v0.2.1
INFO: Installing Polynomials v0.1.0
INFO: Package database updated
INFO: METADATA is out-of-date — you may not have the latest version of ODE
INFO: Use `Pkg.update()` to get the latest versions of your packages
In [13]:
using ODE
INFO: Precompiling module Polynomials.
In [31]:
tout,yout = ode45(f,s,[0.,Tmax])
yhist = hcat(yout...)' # convert to matrix
plot(tout,yhist[:,1])
Out[31]: