Numerical Analysis.

96 Views Asked by At

The problem says:

  • Apply Euler's method with $h=1/4$ to the I.V.P \begin{align} y'_1&=-y_1-y_2,\\ y'_2&=y_1-y_2\end{align} in $[0,1]$ with $y_1(0)=1$, $y_2(0)=0$

  • Verify that $y_1(t)=e^{-t} \cos(t)$ and $y_2(t)=e^{-t}\sin(t)$ is the exact solution.

  • Find the Global Truncations errors of $y_1$ and $y_2$ in $t=1$

For Euler's method I computed: \begin{align} w_{0,1}&=1& &\to& w_{j+1,1}&=1+1/4(-1-0)=3/4\\ w_{0,2}&=0& &\to& w_{j+1,2}&=0+1/4(1-0)=1/4 \end{align} To check that $y_1$ and $y_2$ are solutions is trivial.

The problem I'm stuck with is to find the Global T. Errors, so if if you can help me with that I'd be grateful.

Also if you noticed any mistake in my procedure, please let me know.

1

There are 1 best solutions below

0
On

Just compute the values, to have something to compare to, compute also values for smaller step sizes.

from math import exp, cos, sin

def y1sol(t): return exp(-t)*cos(t)
def y2sol(t): return exp(-t)*sin(t)

def Euler(N):
    ''' print values at k/4 with N Euler steps in between '''
    h = 0.25/N
    t, y1, y2 = 0.0, 1.0, 0.0
    result = "N=%4d: "%N
    for k in range(4):
        for j in range(N):
            y1, y2 = y1 + h*(-y1-y2), y2+h*(y1-y2)
        t += 0.25
        result += "y(%4.2f) = (%10.7f, %10.7f), err = (%8.3e, %8.3e);  "%(t, y1, y2, y1-y1sol(t), y2-y2sol(t))
    print result

for N in [1,10,100]: Euler(N)

with results

N=   1: y(0.25) = ( 0.7500000,  0.2500000), err = (-4.590e-03, 5.732e-02);  y(0.50) = ( 0.5000000,  0.3750000), err = (-3.228e-02, 8.421e-02);  y(0.75) = ( 0.2812500,  0.4062500), err = (-6.438e-02, 8.427e-02);  y(1.00) = ( 0.1093750,  0.3750000), err = (-8.939e-02, 6.544e-02);  
N=  10: y(0.25) = ( 0.7534317,  0.1974906), err = (-1.158e-03, 4.812e-03);  y(0.50) = ( 0.5286568,  0.2975913), err = (-3.624e-03, 6.805e-03);  y(0.75) = ( 0.3395353,  0.3286195), err = (-6.090e-03, 6.636e-03);  y(1.00) = ( 0.1909175,  0.3146473), err = (-7.849e-03, 5.087e-03);  
N= 100: y(0.25) = ( 0.7544698,  0.1931510), err = (-1.200e-04, 4.726e-04);  y(0.50) = ( 0.5319173,  0.2914531), err = (-3.634e-04, 6.668e-04);  y(0.75) = ( 0.3450211,  0.3226329), err = (-6.043e-04, 6.496e-04);  y(1.00) = ( 0.1979911,  0.3100579), err = (-7.750e-04, 4.981e-04);  

The error progression very neatly demonstrates the convergence/global error order 1.