newton's method plotting

66 views (last 30 days)
N/A
N/A on 8 Dec 2020
Edited: Walter Roberson on 11 Dec 2020
here is my code typed out. the hw prompt is below with pictures of my code in mat lab. i keep receiving an error message. once i get the plot to work, i will be able to input my guesses.
inside funq2.m
function (y)=funq2(x);
y=sin(x)-xcos(x);
end
inside citizenone.m
x=-3:0.01:3;
(y)=funq2(x);
plot(x,y)
grid on
  5 Comments
Walter Roberson
Walter Roberson on 11 Dec 2020
Justin:
You could post the solution you found as an Answer and then Accept your Answer.

Sign in to comment.

Answers (1)

David Hill
David Hill on 8 Dec 2020
Something like this:
f=@(x)sin(x)-x.*cos(x);
fp=@(x)cos(x)+x.*sin(x)-cos(x);
x=-3:.01:3;
plot(x,f(x));
%% Newton's Method
X(1)=initialGuess;%provide an initial guess
error=1;
tol=1e-6;%provide a tolerance
count=1;
while error>tol
X(count+1)=X(count)-f(X(count))/fp(X(count));
error=abs(X(count+1)-X(count));%or however you want to determine the error
count=count+1;
end
  3 Comments
N/A
N/A on 8 Dec 2020
Yes, I had it reviewed in my class, yet my teacher does not make sense. I will find a tutor. Thank you for your time.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!