comparison TimeStepper.jl @ 25:1e845cd91cd3

Add Exclamation mark after sten in timeStepper
author Ylva Rydin <ylva.rydin@telia.com>
date Mon, 17 Dec 2018 16:30:39 +0100
parents c4bc1165fdf7
children
comparison
equal deleted inserted replaced
12:c4bc1165fdf7 25:1e845cd91cd3
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