comparison TimeStepper.jl @ 28:32a53cbee6c5

Resolved merge conflict adding plotting function to grid.jl
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Thu, 10 Jan 2019 10:38:42 +0100
parents 1e845cd91cd3
children
comparison
equal deleted inserted replaced
23:9031fe054f2c 28:32a53cbee6c5
4 function getState(ts::TimeStepper) 4 function getState(ts::TimeStepper)
5 error("not implemented") 5 error("not implemented")
6 end 6 end
7 7
8 8
9 function step(ts::TimeStepper) 9 function step!(ts::TimeStepper)
10 error("not implemented") 10 error("not implemented")
11 end 11 end
12 12
13 function stepN(ts::TimeStepper,N::Int) 13 function stepN(ts::TimeStepper,N::Int)
14 for i ∈ 1:N 14 for i ∈ 1:N
43 43
44 function getState(ts::Rk4) 44 function getState(ts::Rk4)
45 return ts.t, ts.v 45 return ts.t, ts.v
46 end 46 end
47 47
48 function step(ts::Rk4) 48 function step!(ts::Rk4)
49 k1 = ts.F(ts.v,ts.t) 49 k1 = ts.F(ts.v,ts.t)
50 k2 = ts.F(ts.v+0.5*ts.k*k1,ts.t+0.5*ts.k) 50 k2 = ts.F(ts.v+0.5*ts.k*k1,ts.t+0.5*ts.k)
51 k3 = ts.F(ts.v+0.5*ts.k*k2,ts.t+0.5*ts.k) 51 k3 = ts.F(ts.v+0.5*ts.k*k2,ts.t+0.5*ts.k)
52 k4 = ts.F(ts.v+ ts.k*k3,ts.t+ ts.k) 52 k4 = ts.F(ts.v+ ts.k*k3,ts.t+ ts.k)
53 ts.v = ts.v + (1/6)*(k1+2*(k2+k3)+k4)*ts.k 53 ts.v = ts.v + (1/6)*(k1+2*(k2+k3)+k4)*ts.k