newton's method plotting

조회 수: 7 (최근 30일)
N/A
N/A 2020년 12월 8일
편집: Walter Roberson 2020년 12월 11일
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
Walter Roberson
Walter Roberson 2020년 12월 11일
Justin comments:
I keep receiving emails to accept the answer for this question. The person did not answer it, I found the answer on my own. Please stop emailing me to accept an answer that was not an answer. Thank you.
Walter Roberson
Walter Roberson 2020년 12월 11일
Justin:
You could post the solution you found as an Answer and then Accept your Answer.

댓글을 달려면 로그인하십시오.

답변 (1개)

David Hill
David Hill 2020년 12월 8일
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
David Hill
David Hill 2020년 12월 8일
You are suppose to use Newton's method to solve. Have you studied Newton's method? I suggest you look at it: https://en.wikipedia.org/wiki/Newton%27s_method
I did not provide a complete solution. You need to plug in your initial guess for the root. The final answer will be in the end of the X array.
N/A
N/A 2020년 12월 8일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by