This preview shows pages 1–3. Sign up to view the full content.
University of California, Berkeley
Department of Mechanical Engineering
Fall Semester 2008
Instructors: M. Frenklach, R. Horowitz
E7, Assignment 11
Assigned: Saturday, November 22, 2008
Due: 12:00 pm (noon), Wednesday, December 3
, 2008
This assignment is an introduction to solving nonlinear equations in MATLAB as well as
an introduction to probability and statistics. As before, turn in the hard copy of your
published file to the drop boxes in Etcheverry 1109 and upload the soft copies of your
script and your functions (the Mfiles) to bspace. Do not forget to name your main Mfile
as lastname_firstname_SID_lab11.m
NOTE: Do not forget to display the contents of your userdefined functions using
the command
type.
MATLAB
commands
*
introduced in this assignment:
rand, randn, hist
1.
a) Write a MATLAB function called
my_bisection
that will perform the bisection
algorithm (as described in class) to find the real roots of a continuous real mathematical
function
f(x)
.
Specifically, the function will have 6 input arguments:
•
fh
: a function handle to a prescribed mathematical function
•
x1
: the lower guess
•
x2
: the upper guess
•
tol
: the desired tolerance value (a positive small number).
•
tol_type
: a character variable that specifies the iteration algorithm’s
termination criterion:
1
1
1

tol_type
'a'
tol_type
'r'
t
o
l
tol_type
'f'
()
t
o
l
kk
k
xx
x
k
fx
+
+
+
−
⇒−
≤
⎧
=
=⇒
⎪
=
⇒≤
⎩
tol
⎪
≤
⎨
Here
x
k
is the kth iteration bisection midpoint.
•
max_iter
: the maximum number of iterations allowed
*
Please refer to
MATLAB
help to learn how to use the functions introduced in this assignment.
Assignment 11
E7
1
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentUniversity of California, Berkeley
Department of Mechanical Engineering
Fall Semester 2008
Instructors: M. Frenklach, R. Horowitz
Here,
max_iter
is the maximum number of iterations to perform until the
termination criterion specified by
tol
and
tol_type
is met.
The outputs of your function
my_bisection
are:
•
root
: the final estimate of the root obtained by the algorithm
•
rhist
: a vector containing the sequence of midpoints obtained by the method
•
niter
: number of iterations performed
•
error
: the final error calculated by the method specified by
tol_type
Here,
rhist
contains the sequence of midpoints
that are calculated by your
bisection algorithm. Hence,
length(rhist)
should return a number equal to
niter
.
If either
x1
or
x2
are roots, then
niter = 0
.
K
,
,
2
1
x
x
Note that the error at the
k
th iteration is a function of the estimates
and
. Since this
poses a problem when we have computed only one estimate (
k
= 1), we will define the
errors at the first iteration to be
=
x1 (
the lower guess).
x
x
1
−
x
x
0
x
Test your function
my_bisection
by finding the roots of the following functions. You
should create the functions as anonymous functions in MATLAB. Specifically, you
should obtain the roots using the 3 different errors specified by
tol_type
and compare
it to the exact result.
This is the end of the preview. Sign up
to
access the rest of the document.
 Spring '09
 Sengupta

Click to edit the document details