User:Egm6341.s10.Team2.GV

From Wikiversity
Jump to navigation Jump to search

Hello World

[Team2]

HW2[edit | edit source]

Problem 8[edit | edit source]

Problem Statement[edit | edit source]

Pg. 6-5

Use 3 methods to find In:

1) Taylor Series Expansion, Fn 2) Composite Trapezoidal Rule 3) Composite Simpson Rule

for n=2,4,8 ... until the error is of order


Solution 1[edit | edit source]

1)Taylor Series Expansion

The goal is to perform the following integration,

The problem with this is that it is an indefinite integral, which must be rewritten in another way in order to analyze it. The method discussed here will be Taylor Series Expansion or McClaurin Series Expansion. The function can be rewritten as follows:

The Taylor Series Expansion for


Using this new definition for the function one can then integrate it directly as follows:



Integrating this for a value of n=2 yields the following:


For n=4:


The percent difference between these two results is calculated as follows:



The following are the results for other values of n until the error is reduced to the power of


Taylor Series
n Estimated Value Percent Difference
n=2 1.25 NA
n=4 1.3160 4.48
n=8 1.3179 0.1445
n=16 1.3179 2.5511e-005
n=32 1.3179 1.6848e-014


Matlab Code used to generate the values for the table:

    function I =taylor(n)
    i=1;
    Itot=0;
    It=0;
    while i<=n
       if i==1
          Itot=1;
       else
            It=1/(factorial(i)*i);
       end
    Itot=Itot+It;
    i=i+1;
    end
    I=Itot;
Solution 2[edit | edit source]

2)Composite Trapezoidal Rule The formula used to analyze the integral for a function using the composite trapezoidal rule is as follows:

It is also necessary to state the following, using L'Hopitals Rule


For n=2 the integration is approximated as follows:

The error is calculated by comparing it to the results obtained using the Taylor Series expansion, as follows:

This table displays the results for similar values:


Composite Trapezoidal Rule
n Estimated Value Percent Difference
n=2 1.3283 0.7883
n=4 1.3205 .1975
n=8 1.3186 0.0494
n=16 1.3181 0.0123
n=32 1.3179 0.0031
n=64 1.3179 7.7187e-004
n=128 1.3179 1.9297e-004
n=256 1.3179 4.8242e-005
n=512 1.3179 1.2061e-005
n=1024 1.3179 3.0151e-006


Matlab Code used to generate the values for the estimates:

    function I=ctrapz(n)
    i=0;
    Itot=0;
    It=0;
    It2=0;
    h=0;
    while i<=n
       if i==0
          Itot1=1;
       else if i<n
            h=1/n;
            It(i)=2*valu(h*i);
           else 
               It2=valu(1);
           end
       end
    Itot=Itot1+sum(It)+It2;
    i=i+1;
    end
    I=Itot/(2*n);
   
    function F= valu(x);
    F=(exp(x)-1)/x;
Solution 3[edit | edit source]

The Composite Simpson's Rule

The rule is defined as follows:

Using this definition the following is found:

Composite Simpson's Rule
n Estimated Value Percent Difference
n=2 1.3180 0.0081
n=4 1.3179 5.133e-4
n=8 1.3179 3.22e-5
n=16 1.3179 2.015e-6


The Following MATLAB code was used to generate the values:

    function I = simpb(a,b,w)
    
    q=1;
    i=a;
    n=0;
    Sum=0;
    c=0;
    
    while n<w
        n=2^q;
        h=(a+b)/n;
    while i<=b
        fx=(exp(i)-1)/(i);
        if i==a
            Sum=1;
        else if i==b
                Sum=Sum+fx;
            else if i==(b-h)
                    Sum=Sum+(4*fx);
                else if rem(c,2)==0
                        Sum=Sum+(2*fx);
                    else
                        Sum=Sum+(4*fx);
                    end
                end
            end
        end
        c=c+1;
        i=i+h;
    end
    n
    In=Sum*(h/3);
    I=In;
    i=a;
    c=0;
    q=q+1;
    Sum=0;
    end


By Comparing all of the methods one is able to conclude that the most efficient method to numerically integrate was the composite Simpson's rule.