Docsity

Practice Problems on Numerical Methods - Homework 4 | CS 257, Assignments of Computer Science

Toggle sidebar
bg1
Homework 4
CS 257
Assigned Date: 3/3/2005
Due Date: 3/15/2005 in class
This assignment has portions to be handed in electronically and portions to be submitted on
paper. Electronic portions are marked [Electronic] and written portions are marked [Written]
. All of the MATLAB functions you write should have the exact name as specified in the
assignment. You will later use a MATLAB program, CheckMP4.p, to submit these functions.
This assignment is intended to serve the following purposes:
•study the solution of non-linear equations with MATLAB;
•have a solid understanding of different methods for root finding;
•examine the behavior of and the difference between these methods.
You are encouraged to plot these functions with MATLAB to see what it looks like before
you start to work on your assignment.
NOTE:
You should not use any MATLAB built-in function for root finding such as fzero in this
assignment. Note also that the lecture notes contain examples of similar MATLAB codes
which you can take as reference.
1. Consider the following non-linear function:
f(x) = 2x−8
Our goal is to examine the behavior of the bisection method when finding the root of
f(x) = 0.
(a) [Electronic] Write a MATLAB function [V, FV] = myBisect(a, b, eps) which
meets the following requirements:
•a,band eps are scalars, where [a, b] is the initial interval and eps is a scalar
accuracy criterion.
•Your function should find a sequence of napproximations to the root using the
bisection method. The iterations should terminate once bi−ai≤eps.
1
pf3
pf4

Partial preview of the text

Download Practice Problems on Numerical Methods - Homework 4 | CS 257 and more Assignments Computer Science in PDF only on Docsity!

Homework 4

CS 257

Assigned Date: 3/3/

Due Date: 3/15/2005 in class

This assignment has portions to be handed in electronically and portions to be submitted on paper. Electronic portions are marked [Electronic] and written portions are marked [Written]

. All of the MATLAB functions you write should have the exact name as specified in the assignment. You will later use a MATLAB program, CheckMP4.p, to submit these functions. This assignment is intended to serve the following purposes:

  • study the solution of non-linear equations with MATLAB;
  • have a solid understanding of different methods for root finding;
  • examine the behavior of and the difference between these methods.

You are encouraged to plot these functions with MATLAB to see what it looks like before you start to work on your assignment.

NOTE:

You should not use any MATLAB built-in function for root finding such as fzero in this assignment. Note also that the lecture notes contain examples of similar MATLAB codes which you can take as reference.

  1. Consider the following non-linear function:

f (x) = 2x^ − 8

Our goal is to examine the behavior of the bisection method when finding the root of f (x) = 0.

(a) [Electronic] Write a MATLAB function [V, FV] = myBisect(a, b, eps) which meets the following requirements:

  • a, b and eps are scalars, where [a, b] is the initial interval and eps is a scalar accuracy criterion.
  • Your function should find a sequence of n approximations to the root using the bisection method. The iterations should terminate once bi − ai ≤ eps.
  • The function should return two vectors: V and FV. V should hold a vector of intervals [ai, bi] resulting from the bisection method. That is, V = [a 1 ,b 1 ; a 2 ,b 2 ; ...; an,bn]. FV should hold the vector of function values at the midpoints of the intervals, that is, FV = [f ((a 1 + b 1 )/2) ; ... ; f ((an + bn)/2)]. (b) [Written] Submit the answers to the following on paper. i. Given the initial points, a=2; b=5, plot two graphs: A. A graph of intervals (ai, bi), where 1 ≤ i ≤ n (just like the red lines in the graph on page 14 of lecture 9). B. A graph of f ((ai + bi)/2), the values at the midpoints obtained above with the bisection method. So the x coordinates are the midpoints, the y coordinates are the values of the function f at the midpoints. ii. Consider modifying the bisection method to be a ”trisection method”, which cuts the current interval into three parts and chooses the left-most interval whose end- points have opposite signs. For example, in the figure below, if the current end points are a and b, we set two new points between them, h1 = a + (b − a)/3 and h2 = a + 2(b − a)/3.

In this case, we notice that f (a) has a different sign from f (h1), and so we choose this interval to be the new interval. Likewise, if f (h1) and f (h2) had opposite signs, we would have chosen [h 1 , h2], and if f (h2) and f (b) had opposite signs we would have chosen [h 2 , b]. Give a formula for the “trisection method”’s accuracy after n iterations. Explain why this method is not better than the bisection method in terms of the number of function evaluations.

  1. This problem has been updated since the first post. The function G to solve, and the initial x0 for problems 2(b)i, 2(b)ii and 2(b)iii have been changed. Consider the following non-linear function:

G(x) =

(x^3 − 4 x^2 + 7x)

Our goal is to solve the fixed point problem G(x) = x.

i. Given the initial points x 0 = 1, x 1 = 1.1, plot a graph of f (x) at the points of (xi; f (xi)), where 1 ≤ i ≤ n, and xi is the i-th approximation to the root you obtained above with the Secant method. Hand in a printout of this plot. ii. Do the xi’s converge with x 0 = 1, x 1 = 1.1? Explain why or why not. iii. Do the xi’s converge with x 0 = 10, x 1 = 10.1? Explain why or why not.

NOTES:

Please note that problems 2 and 3 have been updated since the very first post! You should submit your functions by running the checker program, CheckMP4.p, when they are all completed.

To run the program, download ”CheckMP4.p” posted on CS 257 homepage to your root direc- tory on an EWS UNIX workstation. This should be the same directory in which your three function files are located. Run the checker from inside MATLAB by typing CheckMp4 at the command prompt.

The checker will test your functions, and if they are correct, it will submit an email containing your functions to the graders. Please do not run the checker more than once if your files are correct. You must run the checker from your EWS account, so that the email submission can be properly identified.

Each function must work exactly to our specifications; no partial credit will be given.

Don’t forget to submit your solutions to the written portions either in class or to the TA office by the due date.