Programming a Recursive Function

11 ビュー (過去 30 日間)
MiauMiau
MiauMiau 2013 年 3 月 5 日
Hi
I know in the meantime how to program simple recursive functions, but wondered how Newton's method could be programmed recursively.
Especially, I would like to store for n iterations the resulting values in an vector of length n.
So I would have (as a sketch) something as follows in mind:
function v = newton(n)
% the function
f(n) = x^2;
% the derivative of f
g(n) = 2*x;
x_0 = 1;
for n > 1
v(n) = newton(n-1) - f(newton(n))/g(newton(n))
for n == 1
newton(n) = x_0
end
Could you please help me to correct the code?
Thanks for your efforts

回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by