Question: Implement Newton's method as a function: function , tol ) Note: The derivative will be computed automatically within myNewton.m so that you do not need
Implement Newton's method as a function:
function tol
Note: The derivative will be computed automatically within myNewton.m so that you do not need to input the derivative of
As a class convention, we say that the initial guess counts as iteration. So in a sense, would mean we took one step of Newton's method.
Debugging tips:
If tests and are the only tests failed, and the suggested problem in the "code to call function" is close but not quite correct, then it is likely that you stopped correctly, but did not report the most recent iteration.
are not using the initial condition to start iterating in addition to the suggestion made by Matlab of using ;
Function
function pn myNewtonfxtol
input f anonymous function for root finding problem
input x an initial guess
input tol, a tolerance method will stop when successive iterates are within tol of each other
output p a root fp approx
output n the number of iterations to reach p or the number n when p xn
Compute the derivative and save it as an anonymous function
xsym symx;
fsym fxsym;
fprimesym difffsymxsym;
fprime matlabFunctionfprimesym'vars',xsym;
Code to call your function
As a test, the root of fx xx
define f an initial guess use and use a tolerance of e
send these into the function and store the result as the variable p
the method will converge in iterations
format long to display more digits
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
