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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!