# University of Florida/Egm6341/s10.Team2/HW3

## Problem 1: Proof of tighter error bound for Simpsons Rule (Simple)

#### Problem Statement

• Derive the tighter error bound of the simple Simpson's rule on pg.14-2 for the following two cases by changing the function:

${\displaystyle G\left(t\right):=e\left(t\right)-t^{4}\;e\left(1\right)}$

${\displaystyle G\left(t\right):=e\left(t\right)-t^{6}\;e\left(1\right)}$

Point out where the proof breaks down.

• ${\displaystyle G\left(t\right):=e\left(t\right)-t^{5}\;e\left(1\right)}$ Find if ${\displaystyle G^{\left(3\right)}\left(0\right)=0}$ and follow the same steps as in the proof to see what happens.

#### Problem Solution

##### Derivation of Tighter Error Bound of Simple Simpson's Rule

{\displaystyle {\begin{aligned}E_{2}&={\frac {(b-a)^{5}}{2880}}f^{(4)}(\xi )\\&={\frac {h^{5}}{2880}}f^{(4)}(\xi )\\\end{aligned}}}

${\displaystyle {\mbox{where, }}\quad h={\frac {(b-a)}{2}}}$

Shift origin of x axis to point at ${\displaystyle x_{1}\!}$

${\displaystyle x(t)=x_{1}+ht\!\qquad {\mbox{where, }}t\epsilon [-1,1]\!}$

${\displaystyle {\begin{cases}t=0&,x=x(0)=x_{1}\\t=+1&,x=x(1)=x_{1}+h=x_{2}\\t=-1&,x=x(-1)=x_{0}\\\end{cases}}}$

${\displaystyle E_{2}=I-I_{2}={\frac {(b-a)}{2}}e(1)=h\;e(1)}$

Therefore, ${\displaystyle \;\;-{\frac {h^{5}}{90}}f^{(4)}(\xi )=h\;e(1)}$

${\displaystyle e(1)={\frac {h^{4}}{90}}f^{(4)}(\xi )}$

${\displaystyle e(t)=\int _{-t}^{+t}F(t)dt-{\frac {t}{3}}[F(-t)+4F(0)+F(t)]\qquad {\mbox{where, }}f(x(t))=F(t)}$

By Definition: ${\displaystyle \quad G^{(3)}(\xi _{3})=0}$

• ${\displaystyle G\left(t\right):=e\left(t\right)-t^{4}\;e\left(1\right)}$

${\displaystyle G^{(3)}(t)=e^{(3)}(t)-{\frac {t^{7}}{210}}\;e(1)}$

${\displaystyle G^{(3)}(\xi _{3})=0=e^{(3)}(\xi _{3})-{\frac {{\xi _{3}}^{7}}{210}}\;e(1)}$

{\displaystyle {\begin{aligned}0&=e^{(3)}(\xi _{3})-{\frac {{\xi _{3}}^{7}}{210}}\;e(1)\\e(1)&=e^{(3)}(\xi _{3})\;{\frac {210}{{\xi _{3}}^{7}}}\\\end{aligned}}}

Proof breaks down here. Neglects to properly integrate ${\displaystyle t^{5}\;e(1)}$

• ${\displaystyle G\left(t\right):=e\left(t\right)-t^{6}\;e\left(1\right)}$

${\displaystyle G^{(3)}(t)=e^{(3)}(t)-{\frac {t^{9}}{504}}\;e(1)}$

${\displaystyle G^{(3)}(\xi _{3})=0=e^{(3)}(\xi _{3})-{\frac {{\xi _{3}}^{9}}{504}}\;e(1)}$

{\displaystyle {\begin{aligned}0&=e^{(3)}(\xi _{3})-{\frac {{\xi _{3}}^{9}}{504}}\;e(1)\\e(1)&=e^{(3)}(\xi _{3})\;{\frac {504}{{\xi _{3}}^{9}}}\\\end{aligned}}}

Proof breaks down here. Neglects to properly integrate ${\displaystyle t^{5}\;e(1)}$

##### Solution of Tighter Error Bound Function at t=0

${\displaystyle G\left(t\right):=e\left(t\right)-t^{5}\;e\left(1\right)}$

${\displaystyle G^{(3)}(t)=e^{(3)}(t)-{\frac {t^{8}}{336}}\;e(1)}$

${\displaystyle G^{(3)}(0)=e^{(3)}(0)-{\frac {0^{8}}{336}}\;e(1)}$

${\displaystyle G^{(3)}(0)=-{\frac {2(0)^{2}}{3}}\;[F^{(4)}(0)+90\;e(1)]}$

${\displaystyle G^{(3)}(0)=0\!}$

Solution for problem 1:Egm6341.s10.team2.patodon 10:05, 17 February 2010 (UTC)

## Problem 2: Composite Simpsons Rule Error

#### Problem Statement

Pg. 17-2 Show that the error of the Composite Simpson's Rule is:

${\displaystyle \left|E_{n}^{2}\right|\leq {\frac {(b-a)^{5}}{2880\;n^{4}}}M_{4}={\frac {(b-a)h^{4}}{2880}}M_{4}}$

where ${\displaystyle \;M_{4}}$ is the maximum of ${\displaystyle \quad \left|F^{4}(\zeta )\right|\quad and\quad \zeta \epsilon \left[a,b\right]}$

#### Problem Solution

The error for the Simpson's Composite rule, can be expressed as follows:

${\displaystyle \;E_{n}^{2}=I-I_{n}}$

This error can be rewritten as follows:

${\displaystyle E_{n}^{2}=\int _{a}^{b}f(x)dx-{\frac {h}{3}}\left[f_{0}+4f_{1}+2f_{2}+4f_{3}+2f_{4}...+2f_{n-2}+4f_{n-1}+f_{n}\right]}$

This can be expressed by using the Composite Simpson's rule and dividing the interval 'a' to 'b' into smaller intervals, the error can be expressed as follows:

${\displaystyle E_{n}^{2}=\int _{x_{i}-1}^{x_{i}}f(x)dx-{\frac {h}{3}}\left[f(x_{i-1})+f(x_{i})\right]}$

In this manner the error for simple Simpson's rule can be used to describe the error as follows:

${\displaystyle \left|E_{n}^{2}\right|\leq \left|{\frac {h^{5}}{90}}\underbrace {\sum _{i=1}^{n}maxF^{(4)}(\zeta )} _{\bar {M_{4}}}\right|}$

${\displaystyle {\bar {M_{4}}}\leq n\cdot M_{4}}$

Using this expression the error can then be expressed as follows:

${\displaystyle \left|E_{n}^{2}\right|\leq \left|{\frac {(b-a)^{5}}{2880\;n^{5}}}n\;M_{4}\right|={\frac {(b-a)^{5}}{2880\;n^{4}}}M_{4}}$

${\displaystyle \left|E_{n}^{2}\right|\leq \left|{\frac {(b-a)(b-a)^{4}}{2880\;n^{4}}}M_{4}\right|={\frac {(b-a)h^{4}}{2880}}M_{4}}$

Solution for problem 2: Guillermo Varela

Proofread problem 2: Srikanth Madala 05:22, 18 February 2010 (UTC)

## Problem 3: Using Error Analysis to find n for Taylor Series, Composite trapezoidal rule and Composite Simpon's rule such that error is of the order of (10^-6)

#### Problem Statement

1. Using the error estimates of Taylor Series ,Composite Trapezoidal rule and Composite Simpson's rule estimate ${\displaystyle {\boldsymbol {n}}}$ such that ${\displaystyle {\boldsymbol {E_{n}=I-I_{n}=O(10^{-6})}}}$ and compare against numerical results of HW1.
2. Numerically find the power of the step size h in the error i.e Plot the error vs h on semilog and fit a straight line and measure the slope.

Note: This problem is a logical continuation of problem 8 in HW1. In HW1 it was attempted by iteration to find the value of n. In this problem it is done analytically.All numerical data can be found on the HW1 page linked above and also the corresponding MATLAB codes.

#### Problem Solution

##### Solution: Taylor series

Error is defined as

 ${\displaystyle \displaystyle E_{n}=I-I_{n}=\int _{a}^{b}[f(x)-f_{n}(x)]dx}$

For the Taylor series, from the discussion on p6-4, we know that the error is nothing but the remainder of the Taylor series integrated over the given interval i.e

 ${\displaystyle \displaystyle \int _{a}^{b}R_{n+1}(x)=\int _{a}^{b}\left[{\frac {(x-x_{0})^{n+1}}{(n+1)!}}f^{(n+1)}(\xi )\right]}$ where ${\displaystyle \xi \varepsilon [a,b]}$ (1 p2-3)

For the given function the error is

 ${\displaystyle \displaystyle E_{n}=\int _{0}^{1}\underbrace {\frac {x^{n}}{(n+1)!}} _{w(x)}\underbrace {e^{\xi (x)}} _{g(x)}dx}$ (2)

Using the Integral Mean Value Theorem, we have

 ${\displaystyle \displaystyle E_{n}=e^{\xi (x=\alpha )}\int _{0}^{1}{\frac {x^{n}}{(n+1)!}}dx}$ (3)

integrating we get,

 ${\displaystyle \displaystyle E_{n}=e^{\xi (x=\alpha )}{\frac {1}{(n+1)!(n+1)}}}$ (4)

This function has a minimum when ${\displaystyle \;\alpha =0}$ and maximum when ${\displaystyle \;\alpha =1}$ thus we have

 ${\displaystyle \displaystyle {\frac {1}{(n+1)!(n+1)}}\leq E_{n}\leq {\frac {e}{(n+1)!(n+1)}}}$ (5)

Setting the upper bound of the error to ${\displaystyle \;10^{-6}}$ we have

 ${\displaystyle \displaystyle \ E_{n}\leq {\frac {e}{(n+1)!(n+1)}}=10^{-6}}$ (6)

Solving this equation for ${\displaystyle \;n}$ we get

 ${\displaystyle \displaystyle (n+1)!(n+1)=e*10^{6}\Rightarrow n\approx 7.92=8}$ (A)
In the numerical analysis in problem 8 of HW1 it was seen that the Error for n = 8 was -3.848E-07
##### Solution:Composite Trapezoidal rule

From the discussion on page 16-3 we have

 ${\displaystyle \displaystyle \left|E_{n}^{1}\right|\leq {\frac {(b-a)}{12n^{2}}}M_{2}}$ (1)

where ${\displaystyle \;M_{2}=max\left|f^{(2)}(\zeta )\right|}$ for ${\displaystyle \;\zeta \varepsilon [a,b]}$


For the given function ${\displaystyle \;f(x)={\frac {e^{x}-1}{x}}}$, we have

 ${\displaystyle \displaystyle f^{(2)}(x)={\frac {e^{x}[x^{2}-2x+2]-2}{x^{3}}}}$ (2)

Evaluating over the given interval it is seen that the function ${\displaystyle \;f^{(2)}(x)}$ has maximum value at ${\displaystyle \;x=1}$

 ${\displaystyle \displaystyle M_{2}=f^{(2)}(x=1)={\frac {e[1+2-2]-2}{1}}=0.718282}$ (3)

Setting the error to the ${\displaystyle \;10^{-6}}$ and solving for ${\displaystyle \;n}$ we get

 ${\displaystyle \displaystyle {\frac {(1-0)^{3}}{12n^{2}}}(0.718282)=10^{-6}\Rightarrow n\approx 244.657=245}$ (B)
In the numerical analysis the value of n =245 was found to be 5.872E-07
##### Solution :Composite Simpson's Rule

We have from p 17-2, the error estimate of the Composite Simpson's rule as

 ${\displaystyle \displaystyle \left|E_{n}^{2}\right|\leq {\frac {(b-a)^{5}}{2880n^{4}}}M_{4}}$ (1)

where ${\displaystyle M_{4}=max\left|f^{(4)}(\zeta )\right|}$ for ${\displaystyle \zeta \varepsilon [a,b]}$


For the given function ${\displaystyle f(x)={\frac {e^{x}-1}{x}}}$, we have

 ${\displaystyle \displaystyle f^{(4)}(x)={\frac {e^{x}[x^{4}-4x^{3}+12x^{2}-24x]-24}{x^{5}}}}$ (2)

Evaluating over the given interval it is seen that the function ${\displaystyle \;f^{(2)}(x)}$ has maximum value at ${\displaystyle \;x=1}$

 ${\displaystyle \displaystyle M_{4}=f^{(4)}(x=1)={\frac {e[1-4+12-24+24]-24}{1}}=9(e)-24=0.464536}$ (3)

Setting the error to the ${\displaystyle \;10^{-6}}$ and solving for ${\displaystyle \;n}$ we get

 ${\displaystyle \displaystyle {\frac {(1-0)^{5}}{2880n^{4}}}(0.464536)=10^{-6}\Rightarrow n\approx 3.35735=4}$ (c)
In the numerical analysis the error for n= 4 was 6.717E-06

### Part 2:Numerical determination of power of h

In order to verify the power of ${\displaystyle {\boldsymbol {h}}}$ in the error, data from Problem 8 of HW1 is used.

In the case of a Semilog plot [log(y) vs x], a straight line has an equation of the form

${\displaystyle {\boldsymbol {log(Y)=aX+b}}}$


such that ${\displaystyle {\boldsymbol {Y=e^{(aX+b)}=e^{b}(e^{aX})=ke^{aX}}}}$.From the above equation it is seen that if the plot on a semilog graph is a straight line then the relationship between the two variables is exponential.

A log-log plot(log(y) vs log(x)) is a similar plot, for which the equation is of the form

${\displaystyle {\boldsymbol {log(Y)=a[log(X)]+b}}}$


such that, ${\displaystyle {\boldsymbol {Y=kx^{a};k=e^{b}}}}$.It is readily seen that the slope of the line in the log-log graph is the power of the x variable.

Further reference on the theory of semilog and log plots and methods to fit curves is given below:

1. Semilog plot [[[w:Semi-log_graph]]]
2. Log-Log plot [[[w:Log-log_graph]]]
3. Methods of fitting curves in MATLAB for power and exponential series [[1]]

This discussion is used in the interpretation of the graphs given below.

#### Composite trapezoidal Rule

Given below is the data from the numerical evaluation of the given function using Composite Trapezoidal Rule.[[[Egm6341.s10.Team2/HW1#Solution_1]]]

 Composite Trapezoidal Rule No. of terms ${\displaystyle {\boldsymbol {(n)}}}$ Absolute Error ${\displaystyle {\boldsymbol {(\left|E_{n}^{1}\right|)}}}$ ${\displaystyle {\boldsymbol {h}}}$ 2 1.3282917278 0.5 4 1.3205046195 0.25 8 1.3185530869 0.125 16 1.3180649052 0.0625 32 1.3179428411 0.03125 64 1.3179123240 0.015625 128 1.3179046946 0.0078125 256 1.3179027872 0.00390625 512 1.3179023104 0.001953125 1024 1.3179021912 0.000976563

First we plot a semilog graph for the data. The graph is shown below:

The graph is not a straight line which implies that the relationship between ${\displaystyle {\boldsymbol {h}}}$ and ${\displaystyle {\boldsymbol {log(error)}}}$ is not exponential. Hence we plot a log-log graph as below:

This is seen to be linear. A straight line if fitted to the data the equation of which is given above. From the discussion above, we see that the slope of line is 2.1447 which is very close to the analytical value of 2.

#### Composite Simpson's Rule

Given below is the data obtained from HW1 for the Composite Simpsons Rule.[[[Egm6341.s10.Team2/HW1#Solution_1]]]

 Composite Simpson's Rule No. of terms ${\displaystyle {\boldsymbol {(n)}}}$ Absolute Error ${\displaystyle {\boldsymbol {(\left|E_{n}^{2}\right|)}}}$ ${\displaystyle {\boldsymbol {h}}}$ 2 1.318008666 0.5 4 1.317908917 0.25 8 1.317902576 0.125 16 1.317902178 0.0625

Plotting a semilog graph of ${\displaystyle {\boldsymbol {log(error)}}}$ against ${\displaystyle {\boldsymbol {h}}}$ we see that it is non-linear as in the case of the Composite Trapezoidal Rule.

Thus, plotting the log-log graph as below,

we see that the slope of the line is 4.0881 which is very close to the analytically determined value of 4.

#### Taylor Series

Given below is the data for the Taylor series method.${\displaystyle {\boldsymbol {h}}}$ can be defined for the taylor series as ${\displaystyle (b-a)/n}$ but since ${\displaystyle {\boldsymbol {h}}}$ is not used explicitly in the Taylor series method,it might be of interest to observe how error depends on ${\displaystyle {\boldsymbol {n}}}$,the number of terms of the series. Given below are the plots.Semilog plots and log-log plots can be made of error vs h much like the ones given above, but no linearity is shown in both.

 Taylor Series No. of terms ${\displaystyle {\boldsymbol {(n)}}}$ Absolute Error ${\displaystyle {\boldsymbol {(\left|E_{n}^{2}\right|)}}}$ ${\displaystyle {\boldsymbol {h}}}$ 2 1.2500000 0.5 4 1.3159722222 0.25 8 1.3179018152 0.125 16 1.3179021515 0.0625 32 1.3179021515 0.03125

From this plot it is clearly seen that minimizing the error does not require an infinite series.The error curve is asymptotic and it can be seen that 8 terms gives a very low error.

Solution for problem 3: Niki Nachapa

Proofread problem 3: Guillermo Varela

## Problem 4: Illustrations and comparisons of composite Trapezoidal and composite Simpson's rules

#### Problem Statement

a] Replicate the table 5.1, page 255, Atkinson text book using the composite Trapezoidal rule .

${\displaystyle I=\int _{0}^{\pi }e^{x}\cos \left(x\right)\cdot dx}$

b] Replicate the table 5.3, page 258, Atkinson text book using the composite Simpson's rule .

${\displaystyle I=\int _{0}^{\pi }e^{x}\cos \left(x\right)\cdot dx}$

c] Replicate the table 5.4, page 261, Atkinson text book

${\displaystyle I=\int _{0}^{1}x^{3}{\sqrt {x}}\cdot dx}$

d] Replicate the table 5.5, page 262, Atkinson text book

${\displaystyle I=\int _{0}^{5}{\frac {1}{1+\left(x-\pi \right)^{2}}}\cdot dx}$

e] Replicate the table 5.6, page 262, Atkinson text book

${\displaystyle I=\int _{0}^{1}{\sqrt {x}}\cdot dx}$

f] Replicate the table 5.7, page 263, Atkinson text book

${\displaystyle I=\int _{0}^{2\pi }e^{\cos \left(x\right)}\cdot dx}$

#### Problem Solution

Solution for Part (a):
Here our given Integral is: ${\displaystyle I=\int _{0}^{\pi }e^{x}\cos \left(x\right)\cdot dx}$ where ${\displaystyle f\left(x\right)=e^{x}\cos \left(x\right)}$ is the integrand and ${\displaystyle \;x\in \left[0,\pi \right]}$. We use composite Trapezoidal rule to obtain the following tabulated results:

Trapezoidal rule for evaluating a function- Table 5.1, Atkinson text pg.255

 n-value Numerical Integral (In) True Error (En) Ratio of successive errors (R) Corrected Error (En2) 2 -1738925933/100000000 531891301/100000000 62046637/12500000 4 266720457/20000000 126567653/100000000 4.2 62046637/50000000 8 -1238216243/100000000 31181611/100000000 4.06 31023319/100000000 16 -121480041/10000000 3882889/50000000 4.02 775583/10000000 32 -302243553/25000000 96979/5000000 4.00 1938957/100000000 64 -120751941/10000000 242389/50000000 4.00 484739/100000000 128 -1207155819/100000000 121187/100000000 4.00 24237/20000000 256 -37720779/3125000 3787/12500000 4.00 3787/12500000 512 -603521103/50000000 3787/50000000 4.00 3787/50000000

MATLAB Code:

%Code for evaluating the numerical integrals- 'In' for n=2,4,8,...512, Error values- 'En', Corrected Error Values- 'En2' and ratio of successive errors- 'R' %
syms x;
f=(exp(x)*cos(x));
g=diff(f);
F0=(exp(0)*cos(0));
Fpi=(exp(pi)*cos(pi));
for i=1:1:9
n(i)=2^i;
for k=1:(n(i)+1)
X(k)=((k-1)*(pi/n(i)));
F=(exp(X).*cos(X));
G=sum(F);
In(i)=((pi/n(i))*(sum(F)-(0.5*(F0+Fpi))));
end
I(i)=int(f,0,pi);
En(i)=I(i)-In(i);
En2(i)=-((((pi/n(i))^2)/12)*(subs(g,x,pi)-subs(g,x,0)));
end
round(En*100000000)/100000000;
round(En2*100000000)/100000000;
for i=1:1:8
R(i)=En(i).*(1/En(i+1));
end


Solution for Part (b):
Here our given Integral is: ${\displaystyle I=\int _{0}^{\pi }e^{x}\cos \left(x\right)\cdot dx}$ where ${\displaystyle f\left(x\right)=e^{x}\cos \left(x\right)}$ is the integrand and ${\displaystyle \;x\in \left[0,\pi \right]}$. We use composite Simpson's rule to obtain the following tabulated results:

 Simpson's rule for evaluating a function- Table 5.3, Atkinson text pg.258 n-value Numerical Integral (In) True Error (En) Ratio of successive errors (R) Corrected Error (En2) 2 -407886780413711/35184372088832 -477506763/1000000000 -7354387343260823/4503599627370496 4 -6746923677694755/562949953421312 -427011483/5000000000 55913/10000 -7354387342810463/720575940379 8 -1697886467632563/140737488355328 -7671699/1250000000 8697/625 -3677193678610991/576460752303423488 16 -1698694633809107/140737488355328 -3949931/10000000000 155379/10000 -7354386665469079/18446744073709551616 32 -849373362683185/70368744177664 -248603/10000000000 31777/2000 -3677188721048521/147573952589676412928 64 -6795000020382587/562949953421312 -3113/2000000000 39931/2500 -7354613560421185/4722366482869645213696 128 -3397500420910727/281474976710656 -973/10000000000 159931/10000 -918972517566433/9444732965739290427392

MATLAB Code:

%Code for evaluating the numerical integrals for n=2,4,8,...128, Error values 'Enr', Corrected Error Values 'En2r' and ratio of successive errors- 'Rr' %
clc;
clear;
syms x;
f=(exp(x)*cos(x));
g=diff(f,3);
F0=(exp(0)*cos(0));
Fpi=(exp(pi)*cos(pi));
for i=1:1:9
n(i)=2^i;
for k=1:(n(i)+1)
X(k)=((k-1)*(pi/n(i)));
F=(exp(X).*cos(X));
G=sum(F);
if (mod(k,2)==0)
O(k)=F(k);
E(k)=0;
else
O(k)=0;
E(k)=F(k);
end
end
In(i)=((pi/(3*n(i)))*((4*sum(O))+(2*sum(E))-(F0+Fpi)));
I(i)=int(f,0,pi);
En(i)=I(i)-In(i);
En2(i)=-((((pi/n(i))^4)/180)*(subs(g,x,pi)-subs(g,x,0)));
end
Enr=round(En*10000000000)/10000000000;
En2r=round(En2*10000000000)/10000000000;
for i=1:1:8
R(i)=En(i).*(1/En(i+1));
end
Rr=round(R*10000)/10000;


Solution for Part (c):
Here our given Integral is: ${\displaystyle I=\int _{0}^{1}x^{3}{\sqrt {x}}\cdot dx}$

where ${\displaystyle f\left(x\right)=x^{3}{\sqrt {x}}}$ is the integrand and ${\displaystyle \;x\in \left[0,1\right]}$. We use both composite Trapezoidal and Simpson's rules to obtain the following tabulated results:


 Trapezoidal and Simpson's rule for evaluating a function- Table 5.4, Atkinson text pg.261 n-value Trapezoidal rule True Error (En) Trapezoidal rule Ratio of successive errors (Rr) Simpson's rule True Error (En) Simpson's rule Ratio of successive errors (Rr) 2 -0.0720 3.9618 -0.0034 14.5578 4 -0.0182 3.9898 -0.0002 15.0027 8 -0.0046 3.9973 -1543/100000000 15.3142 16 -0.0011 3.9993 -2519/2500000000 15.5267 32 -0.0003 3.9998 -649/10000000000 15.6715 64 -0.0001 4.0000 -41/10000000000 15.7709 128 -0.000003 4.0000 -3/10000000000 15.8396

MATLAB Code:

%Code for Composite Trapezoidal rule for n=2,4,8,...128 to evaluate Error values: 'Enr' and ratio of successive errors- 'Rr' %
clc;
clear;
syms x;
f=((x^3)*sqrt(x));
g=diff(f);
F0=((0^3)*sqrt(0));
F1=((1^3)*sqrt(1));
for i=1:1:9
n(i)=2^i;
for k=1:(n(i)+1)
X(k)=((k-1)*(1/n(i)));
F(k)=((X(k))^(3.5));
G=sum(F);
In(i)=((1/n(i))*(sum(F)-(0.5*(F0+F1))));
end
I(i)=int(f,0,1);
En(i)=I(i)-In(i);
En2(i)=-((((1/n(i))^2)/12)*(subs(g,x,1)-subs(g,x,0)));
end
Inr=round(In*10000000000)/10000000000;
Enr=round(En*10000000000)/10000000000;
En2r=round(En2*10000000000)/10000000000;
for i=1:1:8
R(i)=En(i).*(1/En(i+1));
end
Rr=round(R*10000)/10000;

%Code for Composite Simpson's rule for n=2,4,8,...128 to evaluate Error values: 'Enr' and ratio of successive errors: 'Rr' %
clc;
clear;
syms x;
f=((x^3)*sqrt(x));
g=diff(f,3);
F0=((0^3)*sqrt(0));
F1=((1^3)*sqrt(1));
for i=1:1:9
n(i)=2^i;
for k=1:(n(i)+1)
X(k)=((k-1)*(1/n(i)));
F(k)=((X(k))^(3.5));
G=sum(F);
if (mod(k,2)==0)
O(k)=F(k);
E(k)=0;
else
O(k)=0;
E(k)=F(k);
end
end
In(i)=((1/(3*n(i)))*((4*sum(O))+(2*sum(E))-(F0+F1)));
I(i)=int(f,0,1);
En(i)=I(i)-In(i);
En2(i)=-((((1/n(i))^4)/180)*(subs(g,x,1)-subs(g,x,0)));
end
Inr=round(In*10000000000)/10000000000;
Enr=round(En*10000000000)/10000000000;
En2r=round(En2*10000000000)/10000000000;
for i=1:1:8
R(i)=En(i).*(1/En(i+1));
end
Rr=round(R*10000)/10000;


Solution for Part (d):
Here our given Integral is: ${\displaystyle I=\int _{0}^{5}{\frac {1}{1+\left(x-\pi \right)^{2}}}\cdot dx}$

where ${\displaystyle f\left(x\right)={\frac {1}{1+\left(x-\pi \right)^{2}}}}$ is the integrand and ${\displaystyle \;x\in \left[0,5\right]}$. We use both composite Trapezoidal and Simpson's rules to obtain the following tabulated results:

 Trapezoidal and Simpson's rule for evaluating a function- Table 5.5, Atkinson text pg.262 n-value Trapezoidal rule True Error (En) Trapezoidal rule Ratio of successive errors (Rr) Simpson's rule True Error (En) Simpson's rule Ratio of successive errors (Rr) 2 1731114401/10000000000 2.4348 -1426645891/5000000000 -7.6920 4 710986397/10000000000 9.4851 370943729/10000000000 -2.7066 8 37479089/5000000000 3.8373 -34262807/2500000000 -129.3779 16 19534027/10000000000 3.9934 1059309/10000000000 98.0853 32 4891607/10000000000 3.9983 27/25000000 16.0159 64 1223407/10000000000 3.9996 337/5000000000 15.9909 128 305883/10000000000 3.9999 21/5000000000 15.9978

MATLAB Code:

%Code for Composite Trapezoidal rule for n=2,4,8,...128 to evaluate Error values: 'Enr' and ratio of successive errors- 'Rr' %
clc;
clear;
syms x;
f=(1/(1+((x-pi)^2)));
g=diff(f);
F0=(1/(1+((0-pi)^2)));
F5=(1/(1+((5-pi)^2)));
for i=1:1:9
n(i)=2^i;
for k=1:(n(i)+1)
X(k)=((k-1)*(5/n(i)));
F(k)=(1/(1+((X(k)-pi)^2)));
G=sum(F);
end
In(i)=((5/n(i))*(sum(F)-(0.5*(F0+F5))));
I(i)=int(f,0,5);
En(i)=I(i)-In(i);
En2(i)=-((((5/n(i))^2)/12)*(subs(g,x,5)-subs(g,x,0)));
end
Inr=round(In*10000000000)/10000000000;
Enr=round(En*10000000000)/10000000000;
En2r=round(En2*10000000000)/10000000000;
for i=1:1:8
R(i)=En(i).*(1/En(i+1));
end
Rr=round(R*10000)/10000;

%Code for Composite Simpson's rule for n=2,4,8,...128 to evaluate Error values: 'Enr' and ratio of successive errors: 'Rr' %
clc;
clear;
syms x;
f=(1/(1+((x-pi)^2)));
g=diff(f,3);
F0=(1/(1+((0-pi)^2)));
F5=(1/(1+((5-pi)^2)));
for i=1:1:9
n(i)=2^i;
for k=1:(n(i)+1)
X(k)=((k-1)*(5/n(i)));
F(k)=(1/(1+((X(k)-pi)^2)));
G=sum(F);
if (mod(k,2)==0)
O(k)=F(k);
E(k)=0;
else
O(k)=0;
E(k)=F(k);
end
end
In(i)=((5/(3*n(i)))*((4*sum(O))+(2*sum(E))-(F0+F5)));
I(i)=int(f,0,5);
En(i)=I(i)-In(i);
En2(i)=-((((5/n(i))^4)/180)*(subs(g,x,5)-subs(g,x,0)));
end
Inr=round(In*10000000000)/10000000000;
Enr=round(En*10000000000)/10000000000;
En2r=round(En2*10000000000)/10000000000;
for i=1:1:8
R(i)=En(i).*(1/En(i+1));
end
Rr=round(R*10000)/10000;


Solution for Part (e):
Here our given Integral is: ${\displaystyle I=\int _{0}^{1}{\sqrt {x}}\cdot dx}$

where ${\displaystyle f\left(x\right)={\sqrt {x}}}$ is the integrand and ${\displaystyle \;x\in \left[0,1\right]}$. We use both composite Trapezoidal and Simpson's rules to obtain the following tabulated results:


 Trapezoidal and Simpson's rule for evaluating a function- Table 5.6, Atkinson text pg.262 n-value Trapezoidal rule True Error (En) Trapezoidal rule Ratio of successive errors (Rr) Simpson's rule True Error (En) Simpson's rule Ratio of successive errors (Rr) 2 0.0631 2.6990 0.0286 2.8200 4 0.0234 2.7393 0.0101 2.8267 8 0.0085 2.7667 0.0036 2.8281 16 0.0031 2.7854 0.0013 2.8284 32 0.0011 2.7983 0.0004 2.8284 64 0.0004 2.8073 0.00015856 2.8284 128 0.0001 2.8136 0.000056 2.8284

MATLAB Code:

%Code for Composite Trapezoidal rule for n=2,4,8,...128 to evaluate Error values: 'Enr' and ratio of successive errors- 'Rr' %
clc;
clear;
syms x;
f=(x^0.5);
g=diff(f);
F0=(0^0.5);
F1=(1^0.5);
for i=1:1:9
n(i)=2^i;
for k=1:(n(i)+1)
X(k)=((k-1)*(1/n(i)));
F(k)=(X(k)^0.5);
G=sum(F);
end
In(i)=((1/n(i))*(sum(F)-(0.5*(F0+F1))));
I(i)=int(f,0,1);
En(i)=I(i)-In(i);
end
Inr=round(In*10000000000)/10000000000;
Enr=round(En*10000000000)/10000000000;
for i=1:1:8
R(i)=En(i).*(1/En(i+1));
end
Rr=round(R*10000)/10000;

%Code for Composite Simpson's rule for n=2,4,8,...128 to evaluate Error values: 'Enr' and ratio of successive errors: 'Rr' %
clc;
clear;
syms x;
f=(x^0.5);
g=diff(f,3);
F0=(0^0.5);
F1=(1^0.5);
for i=1:1:9
n(i)=2^i;
for k=1:(n(i)+1)
X(k)=((k-1)*(1/n(i)));
F(k)=(X(k)^0.5);
G=sum(F);
if (mod(k,2)==0)
O(k)=F(k);
E(k)=0;
else
O(k)=0;
E(k)=F(k);
end
end
In(i)=((1/(3*n(i)))*((4*sum(O))+(2*sum(E))-(F0+F1)));
I(i)=int(f,0,1);
En(i)=I(i)-In(i);
end
Inr=round(In*10000000000)/10000000000;
Enr=round(En*10000000000)/10000000000;
for i=1:1:8
R(i)=En(i).*(1/En(i+1));
end
Rr=round(R*10000)/10000;


Solution for Part (f):
Here our given Integral is: ${\displaystyle I=\int _{0}^{2\pi }e^{\cos \left(x\right)}\cdot dx}$

where ${\displaystyle f\left(x\right)=e^{\cos \left(x\right)}}$ is the integrand and ${\displaystyle \;x\in \left[0,2\pi \right]}$. We use both composite Trapezoidal and Simpson's rules to obtain the following tabulated results:

 Trapezoidal and Simpson's rule for evaluating a function- Table 5.7, Atkinson text pg.263 n-value Trapezoidal rule True Error (En) Trapezoidal rule Ratio of successive errors (Rr) Simpson's rule True Error (En) Simpson's rule Ratio of successive errors (Rr) 2 -1.74053505146400 0.0051* E+04 0.72080057280000 0.0001* E+04 4 -0.03439691882200 2.7480* E+04 0.53431579210000 0.0047* E+04 8 -0.00000125170200 9.7455* E+04 0.01146397070000 2.7477* E+04 16 -0.00000000001300 0.0001* E+04 0.00000041720000 -3.2488* E+04 32 -0.00000000001300 0.0001* E+04 -0.00000000001300 0.0001* E+04 64 -0.00000000001300 0.0001* E+04 -0.00000000001300 0.0001* E+04 128 -0.00000000001300 0.0001* E+04 -0.00000000001300 0.0001* E+04

MATLAB Code:

%Code for Composite Trapezoidal rule for n=2,4,8,...128 to evaluate Error values: 'Enr' and ratio of successive errors- 'Rr' %
clc;
clear;
syms x;
f=exp(cos(x));
g=diff(f);
F0=exp(cos(0));
F2pi=exp(cos(2*pi));
for i=1:1:9
n(i)=2^i;
for k=1:(n(i)+1)
X(k)=((k-1)*((2*pi)/n(i)));
F(k)=exp(cos(X(k)));
G=sum(F);
end
In(i)=(((2*pi)/n(i))*(sum(F)-(0.5*(F0+F2pi))));
I(i)=7.954926521; %from Atkinson text pg.263%
En(i)=I(i)-In(i);
end
Inr=round(In*10000000000)/10000000000;
Enr=round(En*10000000000)/10000000000;
for i=1:1:8
R(i)=En(i).*(1/En(i+1));
end
Rr=round(R*10000)/10000;

%Code for Composite Simpson's rule for n=2,4,8,...128 to evaluate Error values: 'Enr' and ratio of successive errors: 'Rr' %
clc;
clear;
syms x;
f=exp(cos(x));
g=diff(f,3);
F0=exp(cos(0));
F2pi=exp(cos(2*pi));
for i=1:1:9
n(i)=2^i;
for k=1:(n(i)+1)
X(k)=((k-1)*((2*pi)/n(i)));
F(k)=exp(cos(X(k)));
G=sum(F);
if (mod(k,2)==0)
O(k)=F(k);
E(k)=0;
else
O(k)=0;
E(k)=F(k);
end
end
In(i)=(((2*pi)/(3*n(i)))*((4*sum(O))+(2*sum(E))-(F0+F2pi)));
I(i)=7.954926521; %from Atkinson text pg.263%
En(i)=I(i)-In(i);
end
Inr=round(In*10000000000)/10000000000;
Enr=round(En*10000000000)/10000000000;
for i=1:1:8
R(i)=En(i).*(1/En(i+1));
end
Rr=round(R*10000)/10000;


Solution for problem 4: Srikanth Madala 05:22, 18 February 2010 (UTC)

## Problem 5: Romberg Table

#### Problem Statement

Pg. 19-2 (cont'd on Pg. 6-5)

a) Modify the code to make the computation of T(2^j) efficient;

b) Add Romber Table and compare with previous results.

#### Problem Solution

a) Modified code

    function [I1,I2,T1] = trapzoid(f,a,b,n)
h=(b-a)/n;
x=linspace(a,b,n+1);
fx=feval(f,x);
I1=h*(fx(1)/2+sum(fx(2:1:n))+fx(n+1)/2);
n=2*n;
h=(b-a)/n;
x=linspace(a,b,n+1);
fx=feval(f,x);
I2=I1/2+h*sum(fx(2:2:n));
T1=(2^2*I2-I1)/(2^2-1);

    %call function
%I1=To(4),I2=To(8), and T1=T1(4)
format long
[I1,I2,T1]=trapzoid(@(x) (exp(x)-1)./x,eps,1,4)


b) Romberg Table

Convergence is achieved much faster than the composite trapezoidal rule.

Solution for problem 5: