Recursive Function in Matlab (Help)

15 ビュー (過去 30 日間)
Rooter Boy
Rooter Boy 2020 年 10 月 24 日
コメント済み: Rooter Boy 2020 年 11 月 19 日
"My code block does recursion. It's not a "recursive function", as in a function that calls itself, but it does implement a recursion. " I how to convert my code block to recursive function. Can you help me, please?
x=[];
x(1)=1.8;
tol=0.01;
hata=tol+1;
n=1;
itr=0;
while hata>tol
x(n+1)=0.2*(4*x(n)+(32/power(x(n),4)));
hata=abs(x(n+1)-x(n));
n=n+1;
itr=itr+1;
end
I tried but i don't know how to do recursive function for this. You know recursive function should contain your function.
function [itr] = newton(x,tol)
hata=tol+1;
n=1;
itr=0;
while hata>tol
x(n+1)=0.2*(4*x(n)+(32/power(x(n),4)));
hata=abs(x(n+1)-x(n));
n=n+1;
itr=itr+1;
end
I would appreciate if anyone can help.
  2 件のコメント
Rooter Boy
Rooter Boy 2020 年 10 月 24 日
is there anyone to help?

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

採用された回答

Alan Stevens
Alan Stevens 2020 年 10 月 24 日
編集済み: Alan Stevens 2020 年 10 月 24 日
The Newton_Raphson is a recurrence formula, not a recursive one, so what you have written is correct. Look at the last value of x to see the solution.
  1 件のコメント
Rooter Boy
Rooter Boy 2020 年 11 月 19 日
Sir, could you help me when you are available?
https://www.mathworks.com/matlabcentral/answers/652808-nwc-and-lcm-code-block-in-matlab

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNewton-Raphson Method についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by