6
 Unity Univer sity  Department of civil and mining engineering Course: Numerical and computational method Assignment solution Done by: Name ID 1. Ephrem beyene uu57397R 2. Eden Amare uu57096R 3. Adisu getnet uu57725R 4. Nebiyu Dawit uu56428R Submitted to: binyam(MSC) Submission date: 25/11/2014

Numerical and Computational Method Assignment 2

  • Upload
    eph

  • View
    215

  • Download
    0

Embed Size (px)

DESCRIPTION

civil engineering

Citation preview

  • Unity University

    Department of civil and mining engineering

    Course: Numerical and computational method

    Assignment solution

    Done by:

    Name ID

    1. Ephrem beyene uu57397R

    2. Eden Amare uu57096R

    3. Adisu getnet uu57725R

    4. Nebiyu Dawit uu56428R

    Submitted to: binyam(MSC)

    Submission date: 25/11/2014

  • 1.

    %this is a source code for taylor series of cos(x)

    x=input('please input x in radians ');

    sum=0;

    % ea is relative approximation eror

    ea=100;

    %es is the stoping criteria

    es=input('please input stoping criteria ');

    k=0;

    while (ea>es)

    terms=((-1)^k)*(x^(2*k))/factorial(2*k);

    sum=sum+terms;

    %et is the relative true error

    et=abs(((cos(x)-sum)/cos(x))*100);

    ea=abs((terms/sum)*100);

    k=k+1;

    end

    disp('the value of cos x obtained through taylor series is')

    disp(sum)

    disp('the relative true error is')

    disp(et)

    disp('the relative approximation error is')

    disp(ea)

    B. (direct copy paste from math lab)

    Please input x in radians ..pi/3

    Please input stopping criteria .0.5

    The relative true error is

    0.0071

    The relative approximation error is

    0.3664

    The value of cos x obtained through Taylor series is

    0.5000

    2. f(x)=ln (x) given xi=1

    Now lets come up with ln(x) nth derivative.

    f(x)=ln(x)..f(1)=0

    f(x)=1/xf(1)=1

  • f(x)=-1/x2..f(1)=-1

    f(x)=2/x3..f(1)=2

    f(4)(x)=-6/x4f(4)(1)=-6

    And the derivative continues like this.

    (=0 ()( 0))/()! Since this is the basic Taylor series form we can formulate ln x in

    respective manner.

    = (0)( 1)0 + 1( 1)1 1( 1)2

    2! +

    2( 1)3

    3!

    6( 1)4

    4!+

    24( 1)5

    5!

    120( 1)6

    6! .

    = 0 + ( 1) ( 1)2

    2+

    ( 1)3

    3

    ( 1)4

    4+

    ( 1)5

    5

    ( 6)6

    6 ..

    This can be generalized by the summation notation

    = ()( )

    =

    Notice that k starts from one. Its so because the zeroth term is zero and it has no effect on the final

    summation.

    Now the requested mathlab code looks as such;

    x=input('please input number ')

    Sum=0;

    For k=1:1:100

    terms(k+1)=(((((-1)^(k-1))*(x-1)^k))/k);%calculates terms of

    taylor series for ln x.

    sum=sum+terms(k+1);%calculates the value of lnx at each term

    increment.

    et=abs(((log(x)-sum)/log(x))*100);%calculates relative true

    error

    ea=abs((terms(k+1)/sum)*100);%calculates relative

    approximation error

    End

    disp(sum)

    disp(ea)

    disp(et)

  • Analysis of its convergence;

    X values Taylor approximation Relative true error

    1 0 NaN(0)

    2 0.6926 0.0721

    3 -8.4227e+27 7.6667e+29

    4 -3.8556e+45 2.7812e+47

    5 -1.2830e+58 7.9715e+59

    As the table shows after x=2 the series diverges. This can be mathematically shown by ratio test for

    series;

    () =(1)1 ( 1)

    And

    ( + 1) =(1)( 1)+1

    + 1

    lim

    |( + 1)/() |= lim

    (1)+1 (1)+1

    +1*

    (1)(1)

    = lim

    +1( 1)

    =|x-1|

    And for the series to converge, according to ratio test, the term |x-1| must be less than one.by

    this its interval of convergence become; 0

  • et= 0.0015

    The result is very accurate and it could be trusted to four significant figures.

    3. f= @ (x) (x.^3)-(2*x)-5; % this defines the function xl=0; xu=3; ea=100;%ea is relative approximation error es=0.5; xr=0.714285714; i=0; fprintf(' i xl xr xu f(xr)

    ea(percentage) \n') fprintf('========================================================= \n') while(ea>es) xold=xr; %holds the old value of xr for approximation error calculation

    if f(xl)*f(xr)

  • 2 1.75290108 1.95638780 3.00000000 -1.42479279 10.40114432

    3 1.95638780 2.04172202 3.00000000 -0.57226277 4.17952202

    4 2.04172202 2.07481267 3.00000000 -0.21787301 1.59487371

    5 2.07481267 2.08724175 3.00000000 -0.08125173 0.59547902

    6 2.08724175 2.09185353 3.00000000 -0.03006728 0.22046378

    The root is approximately

    2.0919

    The value of f(xr) equals

    -0.0301

    The relative approximation error is

    0.2205