Question
below is the program in matlab using newton's method to find the root at a specific initial point(p0): function p = newton_hw(p0,tol,Nmax) %NEWTON'S METHOD: Enter
below is the program in matlab using newton's method to find the root at a specific initial point(p0):
function p = newton_hw(p0,tol,Nmax) %NEWTON'S METHOD: Enter f(x), f'(x), x0, tol, Nmax f = @(x) x*cos(x)-((sin(x))^2); fp= @(x) -x*sin(x)+ cos(x)-2*sin(x)*cos(x); p = p0 - (f(p0)/fp(p0)); y1=f(p); fprintf('y1=%f',y1) i = 1; while (abs(p - p0) >= tol) p0 = p; p = p0 - f(p0)/fp(p0); i = i + 1; %c=f(p); if (i >= Nmax) fprintf('Fail after %d iterations ',Nmax); break end y=f(p); fprintf('a=%f,y=%f, ',p,y); end end
I want to find all the roots on interval I = [0,5], by selecting initial points at every 0.1, p0=0,.1,.2,...,4.9,5.
so how can i change my program to find where the newton iterates for each of these p0 values with Nmax = 10, and tol = 1e-10
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