Assigned: October 21
Fall 2011
Due: October 28
E7 Laboratory Assignment 9
This assignment is on solving non-linear 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 due-date 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 real-valued 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