assignment4(1)

Download ASSIGNMENT4(1)

If you can't read please download the document

Upload: karen-johnson

Post on 29-Sep-2015

218 views

Category:

Documents


3 download

DESCRIPTION

VJDJ

TRANSCRIPT

  • 1

    Name: BAGARAGAZA Romuald

    Student number: M2014028

    Assagnment 4

    Numerical Analysis

    P203, EXERCISE SET 4.4, 2, f

    QUESTION

    Use the Composite Trapezoidal rule with the indicated values of n to

    approximate the following integrals.

    , n=8

    Solution

    clear

    S=0;

    a=1;

    b=3;

    n=32

    h=(b-a)/n;

    for i=1:n-1

    x(i)=a+i*h;

    end

    S=f(a)+f(b);

    for i=1:n/2-1

    S=S+2*f(x(2*i))+4*f(x(2*i-1));

    end

    S=S+4*f(x(n-1));

    S=h/3*S

    TRUEVALUE=(log(13)-log(5))/2

    S-TRUEVALUE

    f.m

    function ff=f(x)

    ff=x/(x*x+4);

    n= 4

    S = 0.47772983114447

    TRUEVALUE = 0.47775572251372

    ans = -2.589136925290614e-005

    n = 8

    S = 0.47775464628479

    TRUEVALUE = 0.47775572251372

    ans = -1.076228928031942e-006

    n = 16

    S = 0.47775566285229

  • 2

    TRUEVALUE = 0.47775572251372

    ans = -5.966143212798869e-008

    n = 32

    S = 0.47775571889878

    TRUEVALUE = 0.47775572251372

    ans = -3.614939236840087e-009

    P281, EXERCISE SET 5.4 10 (b)

    QUESTION

    Use the Modified Euler method to approximate the solution to each of the

    following initial-value problems, and compare the results to the actual

    values.

    Using the Runge-Kutta method of order four.

    SOLUTION

    a=2;

    b=3;

    N=2;

    h=(b-a)/N;

    t=a;

    w(1)=1;

    for i=1:N+1

    t(i)=a+(i-1)*h;

    end

    for i=1:N

    K1=h*f(t(i),w(i));

    K2=h*f(t(i)+h/2,w(i)+K1/2);

    K3=h*f(t(i)+h/2,w(i)+K2/2);

    K4=h*f(t(i)+h,w(i)+K3);

    w(i+1)=w(i)+(K1+2*K2+2*K3+K4)/6;

    end

    for i=1:N+1

    ww(i)=t(i)+1/(1-t(i));

    end

    for i=1:N+1

  • 3

    error(i)=w(i)-ww(i);

    end

    w

    ww

    error

    f.m

    function ff=f(t,y)

    ff=1+(t-y)^2;