Uka MExer03
Uka MExer03
Uka MExer03
MExer03
1. Evaluate the following integral:
𝟒
∫ (𝟏 − 𝒆−𝒙 )𝒅𝒙
𝟎
(a) analytically, (b) single application of the trapezoidal rule, (c) composite
trapezoidal rule with n = 2 and 4, (d) single application of Simpson’s 1∕3 rule,
(e) composite Simpson’s 1∕3 rule with n = 4, (f) Simpson’s 3∕8 rule, and (g)
composite Simpson’s rule, with n = 5. For each of the numerical estimates (b)
through (g), determine the true percent relative error based on (a).
Given:
a = 0; b = 4
Solution:
Let:
I = answer for the integral
E = relative error of I for each methods with respect to the analytical
value
(a) analytically
𝟒
I = ∫𝟎 (𝟏 − 𝒆−𝒙 )𝒅𝒙
= (x + 𝑒 −𝑥 )|0 to 4
= (4 + e-4) – (0 + e0)
= 3.018315639 ans
I xi f(xi)
0 0 0
1 4 0.981684361
𝑓(𝑥0 )+𝑓(𝑥1 )
I = (𝑏 − 𝑎) 2
0+0.981684361
= (4 − 0) 2
= 1.963368722 ans
@n=2
n = 2; 3 points
h = (b-a)/n = 2
I xi f(xi)
0 0 0
1 2 0.8646647168
2 4 0.981684361
= 2.711013795 ans
@n=4
n = 4; 5 points
h = (b-a)/n = 1
= 2.937840388 ans
3 points required
n=2
h = (b-a)/n = 2
I xi f(xi)
0 0 0
1 2 0.8646647168
2 4 0.981684361
= 2.960228819 ans
4 points required
n = 4 (4 segment); h = (b-a)/n = 1
I xi f(xi)
0 0 0
1 1 0.6321205588
2 2 0.8646647168
3 3 0.9502129316
4 4 0.981684361
I xi f(xi)
0 0 0
1 4/5 0.5506710359
2 8/5 0.798103482
3 12/5 0.9092820467
4 16/5 0.959237796
5 4 0.981684361
ℎ 3ℎ
I = [𝑓(𝑥0 ) + 4𝑓(𝑥1 ) + 𝑓(𝑥2 )] + [𝑓(𝑥2 ) + 3(𝑓(𝑥3 ) + 𝑓(𝑥4 )) + 𝑓(𝑥5 )]
3 8
4 3(4)
=3(5) [0 + 4(0.5506710359) + 0.798103482] + 8(5)
[0.798103482 +
3(0.9092820467 + 0.959237796) + 0.981684361]
= 3.015814245 ans
Summary Discussion:
In this item, the integral was calculated using seven methods.
First is the analytical method (the one that we have learned during
our Integral Calculus class) which gives the result 3.018315639 and is to
be considered as the analytical or real value of the given integral.
Second is single application of trapezoidal rule which has 1 segment
and requires 2 points and the points would be acquired using x = x i + h
and this give the result of 1.963368722 which has an error of 34.95%
relative to the analytical value.
Third is the composite trapezoidal rule given the segment, n of 2
and 4. For n = 2, it requires 3 points and the points would be acquired
using x = xi + h. It gives the result of 2.711013795 with an error of 10.18%
relative to the analytical value. For n = 4, this requires 5 points and the
points would be acquired using x = xi + h. It gives the result of
2.937840388 with an error of 2.67% relative to the analytical value.
Fourth is the single application of Simpson’s 1/3 rule. It requires 3
points and it has 2 segments. To acquire the points, use x = xi + h. It gives
the result of 2.960228819 with an error of 1.92% relative to the analytical
value.
Fifth is the composite Simpson’s 1/3 rule with n = 4. It requires 5
points and the points would be acquired using x = xi + h. It gives the result
of 3.013449252 with an error of 0.16% relative to the analytical value.
Sixth is the Simpson’s 3/8 rule. It has n = 3 and 4 points required,
and the points would be acquired using x = xi + h. It gives the result of
2.991221297 with an error of 0.9% relative to the analytical value.
Seventh is the composite Simpson’s rule with n = 5. It requires 6
points and the points would be acquired using x = xi + h. It gives the result
of 3.015814245 with an error of 0.08% relative to the analytical value.
In conclusion, out of all the methods used, the result from the
composite Simpson’s rule with n=5 presented the value nearest to the
analytical value with only very little relative error.
I xi f(xi)
0 0 1
1 0.1 0.9048
2 0.3 0.7408
3 0.5 0.6065
4 0.7 0.4966
5 0.95 0.3867
6 1.2 0.3012
Evaluate the integral from a = 0 to b = 1.2 using (a) analytical means, (b) the
trapezoidal rule, and (c) a combination of the trapezoidal and Simpson’s rules
wherever possible to attain the highest accuracy. For (b) and (c), compute the
true percent relative error.
In this case, all the given points could be used in solving the integral.
a = 0, b = 1.2
Let
I = the answer for the integral
E = relative error of I for each methods with respect to the
analytical value
Solution:
𝟏.𝟐
I = ∫𝟎 (𝒆−𝒙 )𝒅𝒙
= ( -𝑒 −𝑥 )|0 to 1.2
= (-e-1.2) – (-e0)
= 0.6988057881 ans
n = 6; h = (1.2-0)/n = 0.2
All the given points from the table will be used to solve the integral.
ℎ
I = 2 [𝑓(𝑥0 ) + 𝑓(𝑥6 ) + 2(𝑓(𝑥1 ) + 𝑓(𝑥2 ) + 𝑓(𝑥3 ) + 𝑓(𝑥4 ) + 𝑓(𝑥5 ))]
0.2
= [1 + 0.3012 + 2(0.9048 + 0.7408 + 0.6065 + 0.4966 + 0.3867)]
2
= 0.7011335893 ans
= 0.33 % ans
All the given points from the table will be used to solve the integral.
ℎ
I = 3 [𝑓(𝑥0 ) + 𝑓(𝑥6 ) + 4(𝑓(𝑥1 ) + 𝑓(𝑥3 ) + 𝑓(𝑥5 )) + 2(𝑓(𝑥2 ) + 𝑓(𝑥4 ))]
0.2
= [1 + 0.3012 + 4(0.9048 + 0.6065 + 0.3867) + 2(0.7408 + 0.4966)]
3
= 0.6988119702 ans
= 0.0008847 % ans
Therefore, as we can see, Simpson’s method gives the higher accuracy than
trapezoidal result.
3. Water exerts pressure on the upstream face of a dam as shown in Fig. P19.9.
The pressure can be characterized by
p(z) = ρg(D − z)
Solution:
From the given figure, there were 4 points to be considered as z which were
0,25,50, and 75. The table below presents the values considering the given
formulas above.
h = (b-a)/n = (75-0)/25 = 3
General formula:
ℎ
I = 3 [𝑓(𝑥0 ) + 𝑓(𝑥4 ) + 4(𝑓(𝑥1 ) + 𝑓(𝑥3 ) + ⋯ ) + 2(𝑓(𝑥2 ) + 𝑓(𝑥4 ) + ⋯ )]
𝐷
𝑓𝑡 = ∫ 𝜌𝑔𝑤(𝑧)(𝐷 − 𝑧) 𝑑𝑧
0
ℎ
= 𝜌𝑔 3 [𝑓(𝑥0 ) + 4𝑓(𝑥1 ) + 2(𝑓(𝑥2 ))]
3
= (1000)(9.81) ∗ 3 [9150 + 4(6750) + 2(4325)]
= 439488000 N
= 439488 kN ans
𝐷
∫0 𝜌𝑔𝑧𝑤(𝑧)(𝐷 − 𝑧) 𝑑𝑧
d= 𝐷
∫0 𝜌𝑔𝑤(𝑧)(𝐷 − 𝑧) 𝑑𝑧
10913625 𝑘𝑁−𝑚
=
439488 𝑘𝑁
= 24.83 m ans
where z = the elevation above the deck and H = the height of the mast. The total
force F exerted on the mast can be determined by integrating this function over
the height of the mast:
𝑯
𝑭 = ∫ 𝒇(𝒛)𝒅𝒛
𝟎
(a) Use the composite trapezoidal rule to compute F and d for the case where H
= 30 (n = 6). (b) Repeat (a), but use the composite Simpson’s 1∕3 rule.
Solutions:
(a) Use the composite trapezoidal rule to compute F and d for the case where H
= 30 (n = 6).
With the use of the software MatLab, the following is the code used for
trapezoidal:
function traprule = trapezoidalrule(y,n,a,b)
format long
% y = f(x)
% a = min; b = max
if n == 1;
hh = (b-a);
%diff of x when n = 1
mm = y(a);
%when x = a
lpp = y(b);
%when x = b
traprule = (hh./2).*(mm+lpp);
else
hh = (b-a)./n;
%change of x
h = zeros(n,1);
%vectors of 0 (for loop storing)
z = a:hh:b;
% the intervals
mm = y(z(1));
%initial
for i = 2:n
h(i,:)=2.*y(z(i));
end
lpp=y(z(n+1));%f(xn)
traprule=(hh./2).*(mm+sum(h)+lpp);
end
end
>> y = @(x)200.*(x./(5+x)).*exp((-2.*x)./30)
@(x)200.*(x./(5+x)).*exp((-2.*x)./30)
>> trapezoidalrule(y,6,0,30)
ans = 1.402728197383921e+03
>> F = ans
F = 1.402728197383921e+03
>> y = @(x)(200.*(x./(5+x)).*exp(-2.*x./30)).*x
@(x)(200.*(x./(5+x)).*exp(-2.*x./30)).*x
>> trapezoidalrule(y,6,0,30)
ans = 1.924524045564966e+04
>> ans./F
ans = 13.719864255628359
>> d = ans
d = 13.719864255628359
(b) Repeat (a), but use the composite Simpson’s 1∕3 rule.
With the use of the matlab software, the following is the code used to solve for
the answer using simpson’s rule:
function simpsr = SimpsonsRule(y,n,a,b)
% y = f(x)
format long
hh = (b-a)./n;
% change of x
h = zeros(n,1);
% vectors of 0, loop storing
q = zeros(n,1);
% vectors of 0, storing values
zzz = a:hh:b;
%intervals
mmmm = y(a);
%initial
lp=y(b);
%f(xn)
simpsr=(hh./3).*(mmmm+sum(h)+sum(q)+lp);
end
To acquire the answer for this problem, the following are the commands used:
>> y = @(x) 200.*(x./(5+x)).*exp((-2.*x)./30)
>> SimpsonsRule(y,6,0,30)
ans = 1.462866512831577e+03
>> F = ans
>> SimpsonsRule(y,6,0,30)
ans = 1.940674722514138e+04
>> ans./F
ans = 13.266246137234338
>> d = ans
d = 13.266246137234338