Solutions of Initial Value Problems(IVPs) (Numerical Method)
Euler Method
Formula: $$x_{i+1}=x_i +h f(t_i,x_i)$$
$$\begin{align}\begin{bmatrix}x_{i+1}\\y_{i+1}\end{bmatrix}=\begin{bmatrix}x_i\\y_i\end{bmatrix}+hf(t_i,\begin{bmatrix}x_i\\y_i\end{bmatrix})\end{align}$$
$$\begin{align}\begin{bmatrix}x_{i+1}\\y_{i+1}\end{bmatrix}=\begin{bmatrix}x_i\\y_i\end{bmatrix}+hf(t_i,\begin{bmatrix}x_i\\y_i\end{bmatrix})\end{align}$$
1) Solve $x'=x-t^2 +1$, $0\le t\le 2$, $x(0)=0.5$ with $h=0.2$ using Euler method numerically. Find $x_2$
Solution:$$x_{i+1}=x_i +h f(t_i,x_i)$$
Note that: $t_i=a+ih\Rightarrow t_0=0,t_1=0+0.2=0.2,t_2=0+2(0.2)=0.4,...$
let $i=0,$
$$\begin{align}x_1&=x_0+(0.2)f(t_0,x_0)\\&=0.5+0.2(x_0 - (t_0)^2 +1)\\&=0.5+0.2(0.5-0+1)\\&=0.8\end{align}$$
let $i=1,$
$$\begin{align}x_2&=x_1+(0.2)f(t_1,x_1)\\&=0.8+0.2(0.8-(0.2)^{2}+1)\\&=1.152\end{align}$$
2) $$\begin{cases}x'=x(1-y)&, x(0)=2\\y'=-y(1-x)&, y(0)=1,h=0.1\end{cases}$$
Use Euler method to find $\begin{bmatrix}x_2\\y_2\end{bmatrix}$
Solution:
$$\begin{align}\begin{bmatrix}x_{i+1}\\y_{i+1}\end{bmatrix}=\begin{bmatrix}x_i\\y_i\end{bmatrix}+hf(t_i,\begin{bmatrix}x_i\\y_i\end{bmatrix})\end{align}$$
When $i=0,$
$$\begin{align}\begin{bmatrix}x_{1}\\y_{1}\end{bmatrix}&=\begin{bmatrix}x_0\\y_0\end{bmatrix}+(0.1)f(t_0,\begin{bmatrix}x_0\\y_0\end{bmatrix})\\&=\begin{bmatrix}2\\1\end{bmatrix}+0.1\begin{bmatrix}2(1-1)\\-1(1-2)\end{bmatrix}\\&=\begin{bmatrix}2\\1.1\end{bmatrix}\end{align}$$
When $i=1,$
$$\begin{align}\begin{bmatrix}x_{2}\\y_{2}\end{bmatrix}&=\begin{bmatrix}x_1\\y_1\end{bmatrix}+(0.1)f(t_1,\begin{bmatrix}x_1\\y_1\end{bmatrix})\\&=\begin{bmatrix}2\\1.1\end{bmatrix}+0.1\begin{bmatrix}2(1-1.1)\\-1.1(1-2)\end{bmatrix}\\&=\begin{bmatrix}1.98\\1.21\end{bmatrix}\end{align}$$
Taylor Method
Formula:
$$x_{i+1}=x_i + hf'(t_i,x_i)+\frac{h^2}{2!}f''(t_i,x_i)+\frac{h^3}{3!}f'''(t_i,x_i)+...$$
1) Apply Taylor method of order 4 on $x'=tx^{\frac{1}{3}}$ to find the approximation with $x(1)=1$. Find $x_1$
Solution:
$$x'(t)=f'(x)=tx^{\frac{1}{3}}$$
$$\begin{align}x''(t)=f''(x)&=\frac{d}{dt}(x'(t))\\&=\frac{d}{dt}(tx^{\frac{1}{3}})\\&=x^{\frac{1}{3}}+\frac{1}{3}t^2x^{-\frac{1}{3}}\end{align}$$
$$\begin{align}x'''(t)=f'''(x)&=\frac{d}{dt}(x''(t))\\&=\frac{d}{dt}(x^{\frac{1}{3}}+\frac{1}{3}t^2x^{-\frac{1}{3}})\\&=\frac{1}{3}tx^{-\frac{1}{3}}+\frac{2}{3}t^2x^{-\frac{1}{3}}-\frac{1}{9}t^3x^{-1}\end{align}$$
$$\begin{align}x^{(4)}(t)=f^{(4)}(x)&=\frac{d}{dt}(x'''(t))\\&=\frac{d}{dt}(\frac{1}{3}tx^{-\frac{1}{3}}+\frac{2}{3}t^2x^{-\frac{1}{3}}-\frac{1}{9}t^3x^{-1})\\&=(\frac{1}{3}x^{-\frac{1}{3}}-\frac{1}{9}t^2x^{-1})+(\frac{4}{3}tx^{-\frac{1}{3}}-\frac{2}{9}t^3x^{-1})-(\frac{1}{9}t^2x^{-1}+\frac{1}{9}t^4x^{-\frac{5}{3}})\end{align}$$
let $i=0,$
$$\begin{align}x_1&=x_0 +hf'(t_0,x_0)+\frac{h^2}{2!}f''(t_0,x_0)+\frac{h^3}{3!}f'''(t_0,x_0)+\frac{h^4}{4!}f^{(4)}(t_0,x_0)\\&=1+0.1(1)+\frac{(0.1)^2}{2!}(1+\frac{1}{3})+\frac{(0.1)^3}{3!}(\frac{1}{3}+\frac{2}{3}-\frac{1}{9})+\frac{(0.1)^4}{4!}(\frac{1}{3}-\frac{1}{9}+\frac{4}{3}-\frac{2}{9}-\frac{1}{9}-\frac{1}{9})\\&=1.106819444\end{align}$$
Runge-Kutta Method
Consider the initial value problem $x'=-5x+5t^2+2t,0\le t\le 1, x(0)=1$. Calculate $x_1$
Solution:
let $i=0,$
$$\begin{align}k_1&=f(t_0,x_0)\\&=-5(1)+5(0)^2+2(0)\\&=-5\\x_1&=1+0.1f(0+\frac{0.1}{2},1+\frac{0.1}{2}(-5))\\&=1+0.1f(0.05,0.75)\\&=1+0.1(-5(0.75)+5(0.05)^2+2(0.05))\\&=0.6325\end{align}$$
Solution:
let $i=0,$
$$\begin{align}k_1&=f(t_0,x_0)\\&=-5(1)+5(0)^2+2(0)\\&=-5\\k_2&=f(0+\frac{0.1}{3},1+\frac{0.1}{3}(-5))\\&=f(\frac{1}{30},\frac{5}{6})\\&=-5(\frac{5}{6})+5(\frac{1}{30})^2+2(\frac{1}{30})\\&=-\frac{737}{180}\\k_3&=f(0+\frac{2(0.1)}{3},1+\frac{2(0.1)}{3}(-\frac{737}{180}))\\&=f(\frac{1}{15},\frac{1963}{2700})\\&=-5(\frac{1963}{2700})+5(\frac{1}{15})^2+2(\frac{1}{15})\\&=-\frac{-1879}{540}\\x_1&=x_0+\frac{0.1}{4}(k_1+3k_3)\\&=1+\frac{1}{40}(-5+3(-\frac{1879}{540}))\\&=0.614028\end{align}$$
Formula:
$$\begin{align}k_1&=f(t_i,x_i)\\k_2&=f(t_i+\frac{h}{2},x_i+\frac{h}{2}k_1)\\k_3&=f(t_i+\frac{h}{2},x_i+\frac{h}{2}k_2)\\k_4&=f(t_{i+1},x_i+hk_3)\\x_{i+1}&=x_i+\frac{h}{6}(k_1+2k_2+3k_3+k_4)\end{align}$$
Solution:
let $i=0,$
$$\begin{align}k_1&=f(t_0,x_0)\\&=-5\\k_2&=f(0+\frac{0.1}{2},1+\frac{0.1}{2}(-5))\\&=f(\frac{1}{20},\frac{3}{4})\\&=-5(\frac{3}{4})+5(\frac{1}{20})^2+2(\frac{1}{20})\\&=-\frac{291}{80}\\k_3&=f(0+\frac{0.1}{2},1+\frac{0.1}{2}(-\frac{291}{80}))\\&=f(\frac{1}{20},\frac{1309}{1600})\\&=-5(\frac{1209}{1600})+5(\frac{1}{20})^2+2(\frac{1}{20})\\&=-\frac{1273}{320}\\k_4&=f(0+0.1,1+0.1(-\frac{1273}{320}))\\&=f(0.1,\frac{1927}{3200})\\&=-5(\frac{1927}{3200})+5(0.1)^2+2(0.1)\\&=-\frac{1767}{640}\\x_1&=1+\frac{0.1}{6}(-5+2(-\frac{291}{80})+2(-\frac{1273}{320})+(-\frac{1767}{640}))\\&=0.616796875\end{align}$$
Solution:$$x_{i+1}=x_i +h f(t_i,x_i)$$
Note that: $t_i=a+ih\Rightarrow t_0=0,t_1=0+0.2=0.2,t_2=0+2(0.2)=0.4,...$
let $i=0,$
$$\begin{align}x_1&=x_0+(0.2)f(t_0,x_0)\\&=0.5+0.2(x_0 - (t_0)^2 +1)\\&=0.5+0.2(0.5-0+1)\\&=0.8\end{align}$$
let $i=1,$
$$\begin{align}x_2&=x_1+(0.2)f(t_1,x_1)\\&=0.8+0.2(0.8-(0.2)^{2}+1)\\&=1.152\end{align}$$
2) $$\begin{cases}x'=x(1-y)&, x(0)=2\\y'=-y(1-x)&, y(0)=1,h=0.1\end{cases}$$
Use Euler method to find $\begin{bmatrix}x_2\\y_2\end{bmatrix}$
Solution:
$$\begin{align}\begin{bmatrix}x_{i+1}\\y_{i+1}\end{bmatrix}=\begin{bmatrix}x_i\\y_i\end{bmatrix}+hf(t_i,\begin{bmatrix}x_i\\y_i\end{bmatrix})\end{align}$$
When $i=0,$
$$\begin{align}\begin{bmatrix}x_{1}\\y_{1}\end{bmatrix}&=\begin{bmatrix}x_0\\y_0\end{bmatrix}+(0.1)f(t_0,\begin{bmatrix}x_0\\y_0\end{bmatrix})\\&=\begin{bmatrix}2\\1\end{bmatrix}+0.1\begin{bmatrix}2(1-1)\\-1(1-2)\end{bmatrix}\\&=\begin{bmatrix}2\\1.1\end{bmatrix}\end{align}$$
When $i=1,$
$$\begin{align}\begin{bmatrix}x_{2}\\y_{2}\end{bmatrix}&=\begin{bmatrix}x_1\\y_1\end{bmatrix}+(0.1)f(t_1,\begin{bmatrix}x_1\\y_1\end{bmatrix})\\&=\begin{bmatrix}2\\1.1\end{bmatrix}+0.1\begin{bmatrix}2(1-1.1)\\-1.1(1-2)\end{bmatrix}\\&=\begin{bmatrix}1.98\\1.21\end{bmatrix}\end{align}$$
Taylor Method
Formula:
$$x_{i+1}=x_i + hf'(t_i,x_i)+\frac{h^2}{2!}f''(t_i,x_i)+\frac{h^3}{3!}f'''(t_i,x_i)+...$$
1) Apply Taylor method of order 4 on $x'=tx^{\frac{1}{3}}$ to find the approximation with $x(1)=1$. Find $x_1$
Solution:
$$x'(t)=f'(x)=tx^{\frac{1}{3}}$$
$$\begin{align}x''(t)=f''(x)&=\frac{d}{dt}(x'(t))\\&=\frac{d}{dt}(tx^{\frac{1}{3}})\\&=x^{\frac{1}{3}}+\frac{1}{3}t^2x^{-\frac{1}{3}}\end{align}$$
$$\begin{align}x'''(t)=f'''(x)&=\frac{d}{dt}(x''(t))\\&=\frac{d}{dt}(x^{\frac{1}{3}}+\frac{1}{3}t^2x^{-\frac{1}{3}})\\&=\frac{1}{3}tx^{-\frac{1}{3}}+\frac{2}{3}t^2x^{-\frac{1}{3}}-\frac{1}{9}t^3x^{-1}\end{align}$$
$$\begin{align}x^{(4)}(t)=f^{(4)}(x)&=\frac{d}{dt}(x'''(t))\\&=\frac{d}{dt}(\frac{1}{3}tx^{-\frac{1}{3}}+\frac{2}{3}t^2x^{-\frac{1}{3}}-\frac{1}{9}t^3x^{-1})\\&=(\frac{1}{3}x^{-\frac{1}{3}}-\frac{1}{9}t^2x^{-1})+(\frac{4}{3}tx^{-\frac{1}{3}}-\frac{2}{9}t^3x^{-1})-(\frac{1}{9}t^2x^{-1}+\frac{1}{9}t^4x^{-\frac{5}{3}})\end{align}$$
let $i=0,$
$$\begin{align}x_1&=x_0 +hf'(t_0,x_0)+\frac{h^2}{2!}f''(t_0,x_0)+\frac{h^3}{3!}f'''(t_0,x_0)+\frac{h^4}{4!}f^{(4)}(t_0,x_0)\\&=1+0.1(1)+\frac{(0.1)^2}{2!}(1+\frac{1}{3})+\frac{(0.1)^3}{3!}(\frac{1}{3}+\frac{2}{3}-\frac{1}{9})+\frac{(0.1)^4}{4!}(\frac{1}{3}-\frac{1}{9}+\frac{4}{3}-\frac{2}{9}-\frac{1}{9}-\frac{1}{9})\\&=1.106819444\end{align}$$
Runge-Kutta Method
Consider the initial value problem $x'=-5x+5t^2+2t,0\le t\le 1, x(0)=1$. Calculate $x_1$
- Midpoint method (Runge-Kutta's method of order 2)
Formula:
$$\begin{align}k_1&=f(t_i,x_i)\\x_{i+1}&=x_i + hf(t_i+\frac{h}{2},x_i+\frac{h}{2}k_i)\end{align}$$
Solution:
let $i=0,$
$$\begin{align}k_1&=f(t_0,x_0)\\&=-5(1)+5(0)^2+2(0)\\&=-5\\x_1&=1+0.1f(0+\frac{0.1}{2},1+\frac{0.1}{2}(-5))\\&=1+0.1f(0.05,0.75)\\&=1+0.1(-5(0.75)+5(0.05)^2+2(0.05))\\&=0.6325\end{align}$$
- Heun's third order method (Runge-Kutta's method of order 3)
Formula:
$$\begin{align}k_1&=f(t_i,x_i)\\k_2&=f(t_i+\frac{h}{3},x_i+\frac{h}{3}k_1)\\k_3&=f(t_i+\frac{2h}{3},x_i+\frac{2h}{3}k_2)\\x_{i+1}&=x_i+\frac{h}{4}(k_1+3k_3)\end{align}$$
Solution:
let $i=0,$
$$\begin{align}k_1&=f(t_0,x_0)\\&=-5(1)+5(0)^2+2(0)\\&=-5\\k_2&=f(0+\frac{0.1}{3},1+\frac{0.1}{3}(-5))\\&=f(\frac{1}{30},\frac{5}{6})\\&=-5(\frac{5}{6})+5(\frac{1}{30})^2+2(\frac{1}{30})\\&=-\frac{737}{180}\\k_3&=f(0+\frac{2(0.1)}{3},1+\frac{2(0.1)}{3}(-\frac{737}{180}))\\&=f(\frac{1}{15},\frac{1963}{2700})\\&=-5(\frac{1963}{2700})+5(\frac{1}{15})^2+2(\frac{1}{15})\\&=-\frac{-1879}{540}\\x_1&=x_0+\frac{0.1}{4}(k_1+3k_3)\\&=1+\frac{1}{40}(-5+3(-\frac{1879}{540}))\\&=0.614028\end{align}$$
- Runge-Kutta's method of order 4
Formula:
$$\begin{align}k_1&=f(t_i,x_i)\\k_2&=f(t_i+\frac{h}{2},x_i+\frac{h}{2}k_1)\\k_3&=f(t_i+\frac{h}{2},x_i+\frac{h}{2}k_2)\\k_4&=f(t_{i+1},x_i+hk_3)\\x_{i+1}&=x_i+\frac{h}{6}(k_1+2k_2+3k_3+k_4)\end{align}$$
Solution:
let $i=0,$
$$\begin{align}k_1&=f(t_0,x_0)\\&=-5\\k_2&=f(0+\frac{0.1}{2},1+\frac{0.1}{2}(-5))\\&=f(\frac{1}{20},\frac{3}{4})\\&=-5(\frac{3}{4})+5(\frac{1}{20})^2+2(\frac{1}{20})\\&=-\frac{291}{80}\\k_3&=f(0+\frac{0.1}{2},1+\frac{0.1}{2}(-\frac{291}{80}))\\&=f(\frac{1}{20},\frac{1309}{1600})\\&=-5(\frac{1209}{1600})+5(\frac{1}{20})^2+2(\frac{1}{20})\\&=-\frac{1273}{320}\\k_4&=f(0+0.1,1+0.1(-\frac{1273}{320}))\\&=f(0.1,\frac{1927}{3200})\\&=-5(\frac{1927}{3200})+5(0.1)^2+2(0.1)\\&=-\frac{1767}{640}\\x_1&=1+\frac{0.1}{6}(-5+2(-\frac{291}{80})+2(-\frac{1273}{320})+(-\frac{1767}{640}))\\&=0.616796875\end{align}$$
Comments
Post a Comment