Question
MATLAB 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
MATLAB
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.
% Newton's method in general % excludes zero roots! steps0; x input ( 'Initial guess: , ); re 1e-8; myre1 = 1; % iteration counter % estimate of root % required relative error while myrel re & (steps
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started