

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Computer Laboratory Assignment 04 Due Date: Tuesday, 02/24/
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.
Write a MATLAB function to find the solution of f ( x ) = 0 using Newton’s Method. Recall
Algorithm 1 The pseudocode for Newton’s Method
Input: x 0 , M , δ , ε, f ( x ), f ′( x ) Set v = f ( x 0 ) if | v | ≤ ε then stop for k = 1 to M do x 1 = x 0 − v / f ′( x 0 ) v = f ( x 1 ) if | x 1 − x 0 | ≤ δ or | v | ≤ ε then stop x 0 = x 1 end for
You should write the function in the following form,
[ir,r,err1,err2,numiter]=newton(func1,func2,xinit,delta,eps,maxiter)
where the input arguments
The output arguments
Don’t forget to put sufficient and appropriate comments (explanations) in your MATLAB M file describ- ing, what the function does along with the descriptions of input and output arguments. For example, the following comments are desirable:
% Compute a zero of a given function by Newton’s Method. % The function takes the following input arguments: % func1 = an inline function to be solved. % and so on.....
Having it this way, whenever you type help newton from MATLAB prompt, it will display the com- ments that you have written. Test your procedure to find all roots of the following functions:
f ( x ) = tan( x / 4 ) − 1 with x 0 = 0 f ( x ) = x^3 − 5 x^2 + 3 x − 7 with x 0 = 1000 f ( x ) = x^3 − 3 x + 2 with x 0 = 10 f ( x ) = 7 x^4 + 3 x^2 + π for any x 0.
In all your computations use δ = ε = 1. 0 e − 15.
Modify your code in the previous problem such that it will output a vector containing the sequence of numbers of err1. Let err1(k) be the Newton’s Method error at the k-th iteration. Comment on the convergence of Newton’s Method in all cases (where the method converges) by tabulating err1(k)/err1(k-1) and err1(k)/err1(k-1)^2 , k=2,...,numiter, for all zeros found in Problem 1.
func1 = inline(’x - tan(x)’);
from the MATLAB prompt will create an inline function f ( x ) = x − tan( x ).