I need Help Newton Raphson

5 views (last 30 days)
Mehmet Can Balci
Mehmet Can Balci on 8 Nov 2017
Answered: Steven Lord on 8 Nov 2017
hello worthy readers. Why can't I run this method I can not find a way to make a mistake. Can you help me? Thank you.
function Untitled2(xo,eps,imax)
xr=xo;
iter=0;
fo=f(xo);
dfo=Devf(xo);
while [true]
xrold=xr;
xr=xrold-fo/dfo;
fo=F(xr);
dfo=Devf(xr);
iter=iter+1;
if xr > 0
Ea=Abs((xr-xold)/xr)*100;
end
(Ea < eps) | (Iter>imax)
Untitled2=xr;
  2 Comments
Torsten
Torsten on 8 Nov 2017
Functions f, F (I guess this should be f, too) and Devf are defined elsewhere ?
Best wishes
Torsten.
Mehmet Can Balci
Mehmet Can Balci on 8 Nov 2017
Edited: Mehmet Can Balci on 8 Nov 2017
no function at all. I have not identified elsewhere.
f=@(x) (cos(sqrt(x)))*(cosh(sqrt(x)))+1;This is the function I need to execute.

Sign in to comment.

Answers (1)

Steven Lord
Steven Lord on 8 Nov 2017
Look at this code in the MATLAB Editor. Notice the red square in the upper-right corner of the document? That indicates you have a syntax error in the code that will prevent it from running. Below that square is a bar with orange and red lines. Click on the red line and it will take you to one of the lines that caused Code Analyzer to flag that file as having a syntax error. [In this case you only have one red line.] Hovering over that line or hovering over the red underlined code will also explain why Code Analyzer flagged that line.
Once you've fixed that syntax problem, you have at least one logic problem in your code. When will your while loop ever end? Under what circumstance will the condition controlling the while (in this case true) ever become false? If you look at your homework assignment (this code looks like a fairly standard homework problem) it should tell you under what conditions your loop should end. You need to implement your while so it stops looping under those conditions, either by modifying your while condition or by using the break keyword.
And finally, MATLAB is case sensitive. The line in your code where you call Abs will not call the abs function. If you have written your own Abs function (which probably isn't a good idea, it's too easy to confuse with the abs function) that would work but I think you want abs in all lower case instead.

Categories

Find more on Spline Postprocessing in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!