I need Help Newton Raphson

5 ビュー (過去 30 日間)
Mehmet Can Balci
Mehmet Can Balci 2017 年 11 月 8 日
回答済み: Steven Lord 2017 年 11 月 8 日
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 件のコメント
Torsten
Torsten 2017 年 11 月 8 日
Functions f, F (I guess this should be f, too) and Devf are defined elsewhere ?
Best wishes
Torsten.
Mehmet Can Balci
Mehmet Can Balci 2017 年 11 月 8 日
編集済み: Mehmet Can Balci 2017 年 11 月 8 日
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.

サインインしてコメントする。

回答 (1 件)

Steven Lord
Steven Lord 2017 年 11 月 8 日
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.

カテゴリ

Help Center および File ExchangeSpline Postprocessing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by