Question: The book has two different MATLAB versions of Newton's method. One is a program (on page 162) and the other is a function (page 170).
The book has two different MATLAB versions of Newton's method. One is a program (on page 162) and the other is a function (page 170). The comments on page 162 indicate the algorithm does not work on zero roots (i.e., it does not work when the true root is equal to zero). This is the case because of the form of "myrel".
Create a variation on the function m-file (page 170) in which the zero-root restriction is removed by changing the definition of "myrel." Specifically, do not divide by x; but leave the rest the same.
Then test your modified code on the MATLAB pre-defined "sin" function (and remember your differential calculus: the derivative of sine is simply cosine).
Set the initial guess to pi/4. [You can still name the function "newtfun_LastName.m"].
Create a driver routine named "test_newtfun_LastName.m" that specifies the input arguments and calls newtfun_LastName.m.
[x, conv] Uses Newton's method to solve f (x) 0 fh is handle to f(x), dfh is handle to f (x) Initial guess is xo Returns final value of x, f(x), and conv (1 = convergence, 0 = divergence) newtfun (fh, xo) function % NEWTON f, dfh, % iteration counter steps = 0; x = x0 ; re = 1e-8 ; myre1 = 1 ; % required relative error while myre1 > re (steps re (steps
Step by Step Solution
There are 3 Steps involved in it
To modify the function so it works even when the root is zero you need to change ... View full answer
Get step-by-step solutions from verified subject matter experts
