

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Lab; Professor: Ginting; Class: Numerical Analysis; Subject: Mathematics; University: University of Wyoming; Term: Spring 2009;
Typology: Lab Reports
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Computer Laboratory Assignment 05 Due Date: Tuesday, 04/14/
Write a well documented report of what you did and the answers for all the problems below. It should contain your name and the problem number.
A simple way of computing the area under the curve y = f (x) over interval [a, b] is using the so-called Trapezoidal Rule (see left hand side of the figure):
Area =
∫ (^) b
a
f (x) dx ≈
b − a 2
( f (a) + f (b)).
7
x
f(x)
a b^ a^ b
f(x)
x x 1 x 2 x 3 x 4 x 5 x 6 x
Obviously this is a very crude approximation. Instead we do the following. Divide the interval [a, b]
into M subintervals, where each subinterval (xi− 1 , xi) has width h =
b − a M
, for i = 1 , 2 , · · · , M (see right
hand side of the figure). Note that x 0 = a and xM = b. Next apply the Trapezoidal Rule to each of the subinterval (xi− 1 , xi):
Ti =
xi − xi− 1 2
( f (xi− 1 ) + f (xi)) =
h 2
( f (xi− 1 ) + f (xi)).
Then the area under the curve y = f (x) over interval [a, b] is the sum of all Ti:
M
i= 1
Ti.
This scheme is called Composite Trapezoidal Rule. Your task is to write a function in MATLAB imple- menting this method. The procedure should be of the following form:
function val = CompTrapRule(func,a,b,M)
where
Remark: Direct implementation of the above approximation is not fully efficient because for all internal points, i.e., xi, i = 1 , · · · , M − 1, the function is computed twice. We may actually rewrite the method so that the procedure is more efficient. Expansion of the sum described above yields the following:
M
i= 1
Ai
h 2
M
i= 1
( f (xi− 1 ) + f (xi))
h 2
{( f (x 0 ) + f (x 1 )) + ( f (x 1 ) + f (x 2 )) + ( f (x 2 ) + f (x 3 )) + · · · + ( f (xM− 1 ) + f (xM))}
h 2
( f (a) + f (b)) + h
M− 1
i= 1
f (xi).
This last expression should be implemented in your procedure.
Suppose you are an engineer who has been assigned a job of designing a hinged valve in a dam (see the figure). The valve consists of a hinged circular disk of radius 2 m. The center of the disk is located 4 m below the water surface.
Water Surface
x=a
x=c
x=b
x=d Hinge
x=
Figure 1: Illustration of the valve inside a dam
For the purpose of design you need to remember several definitions: