Computer Laboratory Assignment 5 - Numerical Analysis | MATH 4340, Lab Reports of Mathematical Methods for Numerical Analysis and Optimization

Material Type: Lab; Professor: Ginting; Class: Numerical Analysis; Subject: Mathematics; University: University of Wyoming; Term: Spring 2009;

Typology: Lab Reports

Pre 2010

Uploaded on 08/19/2009

koofers-user-4b7
koofers-user-4b7 🇺🇸

10 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CHE/COSC/MATH 4340-01 Numerical Analysis
Computer Laboratory Assignment 05
Due Date: Tuesday, 04/14/09
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.
Problem 1
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 =Zb
af(x)dx ba
2(f(a) + f(b)).
7
x
f(x)
ab a b
f(x)
x
xxxxxxx1234 56
Obviously this is a very crude approximation. Instead we do the following. Divide the interval [a,b]
into Msubintervals, where each subinterval (xi1,xi)has width h=ba
M, for i=1,2,···,M(see right
hand side of the figure). Note that x0=aand xM=b. Next apply the Trapezoidal Rule to each of the
subinterval (xi1,xi):
Ti=xixi1
2(f(xi1) + f(xi)) = h
2(f(xi1) + f(xi)).
Then the area under the curve y=f(x)over interval [a,b]is the sum of all Ti:
T
M
i=1Ti.
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
func is the function f(x)that govern the curve,
1
pf3

Partial preview of the text

Download Computer Laboratory Assignment 5 - Numerical Analysis | MATH 4340 and more Lab Reports Mathematical Methods for Numerical Analysis and Optimization in PDF only on Docsity!

CHE/COSC/MATH 4340-01 Numerical Analysis

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.

Problem 1

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:

T ≈

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

  • func is the function f (x) that govern the curve,
  • a is the lower limit of the interval,
  • b is the upper limit of the interval,
  • M is the number of subintervals,
  • val is the value of the approximated integration.

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:

T ≈

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.

Problem 2

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: