Assigned: October 21
Fall 2011
Due: October 28
E7 Laboratory Assignment 9
This assignment is on solving nonlinear equations in Matlab and an introduction to Linear Algebra.
Note:
You will use MATLAB’s
publish
command (accessible in the Editor window via
File >
Publish
Filename
) to generate a printable document that contains your code and your answers.
1. You must turn in a printed copy to the homework boxes in room 1109 Etcheverry.
Further, you will
need to use the command
type
to display your functions in your main script. You will not get
credit for the functions you have written unless you display them!
Be sure to turn your printout
into the box corresponding to the lab section in which you are registered. The duedate is 12:00 pm
(noon) on October 28.
2. Your primary mﬁle, which is used to generate the HTML document, and all of the function mﬁles
that you create must also be uploaded to bSpace (under the
Assignments
tab) by noon on October
28.
Please (i) have your full name, student ID number, and lab section number at the head of the ﬁle and
(ii) name this ﬁle
lastname
middlename
firstname
lab09.m
.
Use the
”clear;format compact”
command at the beginning of your script to clear the variables from
the base workspace and format appropriately to reduce the length of the output. If your comments
exceed the page border, highlight the comment and go to
Text
>
Wrap Comment
.
In several problems, you are asked to execute a number of given lines, and explain (in a comment before
the line) what the command does. Some lines might produce an error (this is deliberate, on our part).
In that case, after you understand what is the issue, comment out that line (using the
%
symbol) in
your script ﬁle and explain why the error occurred.
Part A: Bisection method and Newton’s method
1. Write a MATLAB function called
bisectE7
that will perform the bisection algorithm to ﬁnd the
real roots of a realvalued function
f
. The function declaration line should be:
begin code
1
function [r,rhistory,N,fError] = bisectE7(fHan,xL,xR,fTol,iterMax)
end code
The input arguments are:
•
fHan
: function handle of the function
f
;
•
xL
: scalar,
double
, represents
x
left
;
•
xR
: scalar,
double
, represents
x
right
;
•
fTol
: stopping tolerance, used for absolute value of the function;
•
interMax
: maximum number of iterations allowed.
The outputs of
bisectE7
are:
1 of 10
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentAssigned: October 21
Fall 2011
Due: October 28
•
r
: the ﬁnal estimate of the root obtained by the algorithm
•
rhistory
: a vector containing the sequence of midpoints obtained by the algorithm
•
N
: the number of iterations performed
•
fError
: the absolute value of the function evaluated at the computed solution
The function
bisectE7
should ﬁrst check if either
x
L
or
x
R
satisfy the stopping criteria speciﬁed
by
fTol
. If one (or both) satisfy the criteria, then that value (or the one that makes

f
(
x
)

smallest) should be returned as the root, with
N
, the iteration count, set to
This is the end of the preview.
Sign up
to
access the rest of the document.
 Fall '08
 Patzek
 Continuous function, Bisection Method, rhistory

Click to edit the document details