b−a n π h f x x x …+2 f x f x π f (0) +2 f π f (π) π f (0) +2 f π π f (π) π
b−a n π h f x x x …+2 f x f x π f (0) +2 f π f (π) π f (0) +2 f π π f (π) π
b−a π
a) For n = 2, h= =
n 2
h
T n= f ( x 0 ) +2 f ( x 1) + 2 f ( x2 ) + …+2 f ( x n−1) + f ( x n ) ]
2[
π π
T 2=
2 [
f ( 0 )+2 f
2()
+ f ( π ) =0
]
π π π 3π
For n = 4, T 4=
8 [
f ( 0 ) +2 f
4 () () ( )
+2 f
2
+2 f
4
+f (π )
]
π
¿ ¿
8
Using MATLAB, T 8=−5.6859, T 16=−6.3690, T 32=−6.6192, T 64=−6.7092,
T 128=−6.7413, T 256 =−6.7527, T 512=−6.7567, T 1024=−6.7582.
b−a π
b) For n = 2, h= =
n 2
h
Sn = f ( x ) + 4 f ( x 1 ) +2 f ( x 2 ) +…+ 4 f ( x n−1 ) + f ( xn ) ]
3[ 0
π π
S2 =
6 [
f ( 0 ) +4 f
2 ()
+ f ( π ) =0
]
π π π 3π
For n = 4, S4 =
12[f ( 0 )+ 4 f
4 () () ( )
+2 f
2
+4 f
4
+f ( π)
]
π
¿ ¿
12
Using MATLAB, S8=−6.2802, S16−6.5967 , S32=−6.7026 , S64=−6.7392,
S128 =−6.7520 , S256 =−6.7565 , S512 −6.7581, S1024 =−6.7586 .
Both methods converge in an almost linear fashion, and it seems like Simpson’s method
converges a bit faster than the Trapezoidal method.
c) The 1-point Gauss quadrature approximation is given by:
Problem 2:
For the Trapezoidal rule
3
k ( b−a) b−a
|Error|≤ with k ≤ f ' ' ( x) and n=
12n 2
h
k (b−a)3 k h2 (b−a)
|Error|≤ =
12n 2 12
The maximum value of f ' ' ( x) on the given interval is f ' ' (1)=70.9183 which will be the
value of k for our upper bound.
k ( b−a)5 b−a
|Error|≤ with k ≤ f (4) (x ) and n=
180 n 4
h
5 2
k (b−a) k h (b−a)
|Error|≤ =
180 n 4 180
The maximum value of f (4 ) (x) on the given interval is f ' ' (0.893)=395.9 which will be the
value of k for our upper bound.
791.8 h4 −10
=10 ; h=2.183555585× 10−3
180
b−a 2
Therefore, n= = =915.937=916
h 2.183555585 ×10−3
Using the MATLAB code to find the value of the Trapezoidal rule approximation, we get that
the corresponding absolute error is 4.87812423345189981 ×10−11 .
We notice that Simpson’s rule achieves the same accuracy as the Trapezoidal rule with a
significantly fewer number of iterations.
Problem 3:
Let f ( x )=ax+ b
1 1
∫ √ x f ( x )=∫ √ x ( a x+ b )
0 0
1
x5 / 2 x 3 /2
I =∫ ( a x 3 /2 +b x 1/ 2) dx =a×
0 5 /2
+b ×
3 /2 |
⟹ I= ( 25 a+ 23 b )= 23 ( 35 a+ b)=w f ( x )
1 1
2 3
Therefore, w 1= and x 1=
3 5
2 3
⟹I≈ f
3 5 ()
For f ( x )=cos x ≈ 1 (linear polynomial)
1
2
⟹ I =∫ √ x f ( x ) ≈
0 3
1
{ 2
} 2
error = ∫ √ x cos x − =0.5312− =0.1355
0 3 3