summaryrefslogtreecommitdiffstats
path: root/notes/lec07_intro2_eulers
blob: 17630d236cf55df393dbf62ef03c6c9af569ae4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

euler's method:

dx/dt =~ ( x(t + Dt) - x(t) ) / Dt, for very small Dt

so, x(t + Dt) = x(t) + f(x) * Dt, which is how to integrate the system

"if Dt is too large, becomes highly unstable" (duh)

scary MATLAB advice:
- watch out of totally crazy values (very high)
- non-negative values go negative

MATLAB built-in ODE solvers: ode23, ode15s

runge-kutta (use dxdt from between t_n and t_(n+1) )
variable time-step methods

summary: Euler's method sucks, news at 11.

### misc julia notes

the only place to find history (?!?!!) is in ~/.julia_history

### codes

using Winston

a=20
b=2
c=5
dt = 0.05
tlast = 2

iterations = int( round(tlast/dt) )
xall = zeros(iterations, 1)
x = c

for i = 1:iterations
    xall[i] = x
    dxdt = a - b*x
    x = x + dxdt*dt
end

time = dt * [0:iterations-1]'
plot(time,xall)