Sec 25 1 EULERS METHOD Sec 25 1

  • Slides: 13
Download presentation
Sec: 25. 1 EULER’S METHOD

Sec: 25. 1 EULER’S METHOD

Sec: 25. 1 EULER’S METHOD We approximate: by: We divide [a, b] step-size Initial

Sec: 25. 1 EULER’S METHOD We approximate: by: We divide [a, b] step-size Initial Value Problem Euler’s Method

Sec: 25. 1 EULER’S METHOD Example Use Euler’s method with h = 0. 4

Sec: 25. 1 EULER’S METHOD Example Use Euler’s method with h = 0. 4 to approximate the solutions for the following initial-value problems Euler’s Method 0. 0 0. 5000 0. 4 1. 1000 1. 2141 0. 8 1. 8760 2. 1272 1. 2 2. 7704 3. 1799 1. 6 3. 7026 4. 2835 2. 0 4. 5596 5. 3055

Sec: 25. 1 EULER’S METHOD Example Euler’s Method 0. 0 0. 5000 0. 4

Sec: 25. 1 EULER’S METHOD Example Euler’s Method 0. 0 0. 5000 0. 4 1. 1000 1. 2141 0. 8 1. 8760 2. 1272 1. 2 2. 7704 3. 1799 1. 6 3. 7026 4. 2835 2. 0 4. 5596 5. 3055 2. 4 5. 1834 6. 0484 2. 8 5. 3528 6. 2177 3. 2 4. 7579 5. 3737 3. 6 2. 9651 2. 8609 4. 0 -0. 6329 -2. 2991

Sec: 25. 1 EULER’S METHOD clear; clc f = @(t, y) y - t.

Sec: 25. 1 EULER’S METHOD clear; clc f = @(t, y) y - t. ^2 +1; y_true = @(t) (t+1). ^2 - 0. 5*exp(t); a=0; b =4; alpha = 0. 5; w(1) = alpha; n=10; h =(b-a)/n; t=a: h: b; for i = 1: n w(i+1) = w(i) + h*f(t(i), w(i)); end hh=(b-a)/1000; y_t = y_true(a: hh: b); plot(t(1: n+1), w, '-or', a: hh: b, y_t, 'b-'); grid on Example Euler’s Method

Sec: 25. 1 EULER’S METHOD pp. 750 25. 1 Solve the following initial value

Sec: 25. 1 EULER’S METHOD pp. 750 25. 1 Solve the following initial value problem over the interval from t = 0 to 2 where y(0) = 1. Display all your results on the same graph. (a) Euler’s method with h = 0. 5 and 0. 25. 0. 0000 1. 0000 0. 5000 0. 2500 1. 0000 0. 0781 1. 5000 0. 0586 2. 0000 0. 1135 Euler’s Method

Sec: 25. 1 EULER’S METHOD pp. 750 25. 1 Solve the following initial value

Sec: 25. 1 EULER’S METHOD pp. 750 25. 1 Solve the following initial value problem over the interval from t = 0 to 2 where y(0) = 1. Display all your results on the same graph. (a) Euler’s method with h = 0. 5 and 0. 25. 0. 0000 1. 0000 0. 5000 0. 2500 1. 0000 0. 0781 1. 5000 0. 0586 2. 0000 0. 1135 This code will solve the problem with h=0. 5. Change to solve h=0. 25 ? clear; clc f = @(t, y) y. * t. ^3 -1. 5*y; a=0; b =2; alpha = 1; w(1) = alpha; n=4; h =(b-a)/n; t=a: h: b; for i = 1: n w(i+1) = w(i) + h*f(t(i), w(i)); end [t' w']

Sec: 25. 1 EULER’S METHOD Euler’s Method Initial Value Problem (*) We will use

Sec: 25. 1 EULER’S METHOD Euler’s Method Initial Value Problem (*) We will use Taylor’s Theorem to derive Euler’s method.

Sec: 25. 1 EULER’S METHOD Euler’s Method Example Exact calculation (no round-off error) local

Sec: 25. 1 EULER’S METHOD Euler’s Method Example Exact calculation (no round-off error) local truncation error propagated truncation error

Sec: 25. 1 EULER’S METHOD

Sec: 25. 1 EULER’S METHOD

Sec: 25. 1 EULER’S METHOD Example clear; clc f = @(t, y) t*abs(y); y_true

Sec: 25. 1 EULER’S METHOD Example clear; clc f = @(t, y) t*abs(y); y_true = @(t) exp(t. ^2/2); a=0; b =3; alpha = 1; w(1) = alpha; n=10; h =(b-a)/n, t=a: h: b; for i = 1: n w(i+1) = w(i) + h*f(t(i), w(i)); end hh=(b-a)/1000; y_t = y_true(a: hh: b); plot(t(1: n+1), w, '-or', a: hh: b, y_t, 'b-'); grid on clear; clc; syms y(t) ode 1 = diff(y, t) == t*abs(y) cond 1 = y(0) == 1; y 1 Sol(t) = dsolve(ode 1, cond 1) f 1 = @(t) y 1 Sol(t);

Sec: 25. 1 EULER’S METHOD Example Matrix Form Euler’s Method Matrix Form

Sec: 25. 1 EULER’S METHOD Example Matrix Form Euler’s Method Matrix Form

Sec: 25. 1 EULER’S METHOD Example Euler’s Method clear; clc F = @(t, Y)

Sec: 25. 1 EULER’S METHOD Example Euler’s Method clear; clc F = @(t, Y) [Y(1)-2*Y(2)+1; t-Y(1)+Y(2)]; a=0; b =2; alpha = [2; -1]; W(: , 1) = alpha; n=100; h =(b-a)/n, t=a: h: b; for i = 1: n W(: , i+1) = W(: , i) + h*F(t(i), W(: , i)); end plot(t(1: n+1), W(1, : ), '-r', t(1: n+1), W(2, : ), '-b'); grid on