# Numerical Analysis/Exercises

1)Solve differential equation y' = 2ty in [0,1] using Euler's method with n=10,y(0)=1.
Solution:
We need to find the solution ODE y' = 3t$^2$y using Euler's method.
y$_{n+1}$=y$_n$+hf(t$_n$,y$_n$)
We divide time span with number points to find the step size h.
h=tmax-tmin/n=1-0/10=0.1
y$_1$=y$_0$+hf(t$_0$,y$_0$)
=1.000000+.1x3x0$^2$x1
=1.000000
y$_2$=y$_1$+hf(t$_1$,y$_1$)
=1.000000+.1x3x0.1$^2$x1.000000
=1.003000
y$_3$=y$_2$+hf(t$_2$,y$_2$)
=1.003000+.1x3x0.2$^2$x1.003000
=1.0150360
y$_4$=y$_3$+hf(t$_3$,y$_3$)
=1.01503600+.1x3x0.3$^2$x1.0150360
=1.0424420
y$_5$=y$_4$+hf(t$_4$,y$_4$)
=1.0424420+.1x3x0.4$^2$x1.0424420
=1.0924792
y$_6$=y$_5$+hf(t$_5$,y$_5$)
=1.0924792+.1x3x0.5$^2$x1.0924792
=1.1744151
y$_7$=y$_6$+hf(t$_6$,y$_6$)
=1.1744151+.1x3x0.6$^2$x1.1744151
=1.3012520
y$_8$=y$_7$+hf(t$_7$,y$_7$)
=1.3012520+.1x3x0.7$^2$x1.3012520
=1.4925360
y$_9$=y$_8$+hf(t$_8$,y$_8$)
=1.4925360+.1x3x0.8$^2$x1.4925360
=1.7791029
y$_{10}$=y$_9$+hf(t$_9$,y$_9$)
=1.77910290+.1x3x0.9$^2$x1.7791029
=2.2114249
2)Solve differential equation y' = 2ty in [0,1] using RK2 method y$_{n+1}$=y$_n$+h/4(k$_1$+3K$_2$) where k$_1$=f(t$_n$,y$_n$),k$_2$=f(t$_n$+2/3h,y$_n$+2/3hk$_1$)with n=5,y(0)=1.
Solution:
We need to find the solution ODE y' = 2ty using RK second order method.
y$_{n+1}$=y$_n$+h/4(k$_1$+3K$_2$)
k$_1$=f(t$_n$,y$_n$)
k$_2$=f(t$_n$+2/3h,y$_n$+2/3hk$_1$)
y$_1$=y$_0$+h/4(k$_1$+3K$_2$)
k$_1$=f(t$_0$,y$_0$)
=2x0.0x1
=0
k$_2$=f(t$_0$+2/3h,y$_0$+2/3hk$_1$)
=2x2/3x0.2x1
=0.26667
y$_1$=y$_0$+h/4(k$_1$+3K$_2$)
=1+0.2/4(0+3x0.26667)
=1.04
y$_2$=y$_1$+h/4(k$_1$+3K$_2$)
k$_1$=f(t$_1$,y$_1$)
=2x0.2x1.04
=0.416
k$_2$=f(t$_1$+2/3h,y$_1$+2/3hk$_1$)
=f(0.2+0.13333,1.04+0.0554667)
=0.730304
y$_2$=y$_1$+h/4(k$_1$+3K$_2$)
=1.04+.2/4(0.416+3x0.730304)
=1.17035
y$_3$=y$_2$+h/4(k$_1$+3K$_2$)
k$_1$=f(t$_2$,y$_2$)
=2x0.4x1.17035
=0.93648
k$_2$=f(t$_2$+2/3h,y$_2$+2/3hk$_1$)
=f(0.4+2/3(0.2),1.17035+2/3(0.2)(0.93648))
=1.34316
y$_3$=y$_2$+h/4(k$_1$+3K$_2$)
=1.17035+0.2/4(0.93648+3(1.34318))
=1.41865
y$_4$=y$_3$+h/4(k$_1$+3K$_2$)
k$_1$=f(t$_3$,y$_3$)
=f(0.6,1.41865)
= 1.70238
k$_2$=f(t$_3$+2/3h,y$_3$+2/3xhxk$_1$)
=f(.6+.133333,1.41865+2/3(0.2)(1.70238))
=1.64563
y$_4$=y$_3$+h/4(k$_1$+3K$_2$)
=1.41865+.2/4(1.72038+3(1.64563))
=1.75061
y$_5$=y$_4$+h/4(k$_1$+3K)
k$_1$=f(t$_4$,y$_4$)
=f(0.8,1.75061)
= 2.800098
k$_2$=f(t$_4$+2/3h,y$_4$+2/3hk$_1$)
=f(0.8+.133333,1.75061+2/3(0.2)(2.800098))
=3.96472
y$_5$=y$_4$+h/4(k$_1$+3K$_2$)
=1.75061+.2/4(2.800098+3(3.96472))
=2.48532
y$_6$=y$_5$+h/4(k$_1$+3K$_2$)
k$_1$=f(t$_5$,y$_5$)
=f(1,2.48532)
= 4.97064
k$_2$=f(t$_5$+2/3h,y$_5$+2/3hk$_1$)
=f(1+.133333,2.48532+2/3(0.2)(4.97064))
=7.1356
y$_6$=y$_5$+h/4(k$_1$+3K$_2$)
=2.48532+.2/4(4.97064+3(7.1356))
=3.80420
3)Solve differential equation y' = 2ty in [0,1] using Two step Adams Bashforth method with n=5,y(0)=1.
We need to find the solution ODE y' = 2ty using Two step Adams Bashforth method.
y$_{n+2}$ = y$_{n+1}$ + 3/2 x hf(t$_{n+1}$,y$_{n+1}$)-1/2 x hf(t$_n$,y$_n$)
Calculating h=1-0/5=0.2
We need two approxmations for calculating y$_2$
Calculating y$_1$ using RK second order method.
y$_1$=1.04
y$_2$ = y$_1$ + 3/2 x hf(t$_1$,y$_1$)-1/2 x hf(t$_0$,y$_0$)
=1.04+3/2(.2)f(0.2,1.04)-1/2(0.2)f(0.0,1)
=1.1648
y$_3$ = y$_2$ + 3/2 x hf(t$_2$,y$_2$)-1/2 x hf(t$_1$,y$_1$)
=1.1648+3/2(.2)f(0.4,1.1648)-1/2(0.2)f(0.2,1.04)
=1.40275
y$_4$ = y$_3$ + 3/2 x hf(t$_2$,y$_2$)-1/2 x hf(t$_2$,y$_2$)
=1.40275+3/2(.2)f(0.6,1.40275)-1/2(0.2)f(0.4,1.1648)
=1.81456
y$_5$ = y$_4$ + 3/2 x hf(t$_4$,y$_4$)-1/2 x hf(t$_3$,y$_3$)
=1.81456+3/2(.2)f(0.8,1.81456)-1/2(0.2)f(0.6,1.40275)
=2.21333
y$_6$ = y$_5$ + 3/2 x hf(t$_5$,y$_5$)-1/2 x hf(t$_4$,y$_4$)
=2.21333+3/2(.2)f(1,2.21333)-1/2(0.2)f(0.8,1.81456)
=3.25098