フィルターのクリア

trouble of taking derivative of function in newton method

1 回表示 (過去 30 日間)
kingsley
kingsley 2017 年 5 月 13 日
編集済み: kingsley 2017 年 5 月 13 日
I'm trying to write a code for newton method. But I'm having a trouble of taking the derivative of the function(f(x(i))). Here is the code I have:
function [root]=newton_method(f, xi, tol, maxn) % f is function handle
syms x
for i= 1:maxn
fprime = diff(f(x(i)),xi);
root=xi-f(x(i)/fprime);
if abs (x(i)-root)< tol
root=x(i);
break
end
end
end
Can someone tell me how to fix it?
  2 件のコメント
John D'Errico
John D'Errico 2017 年 5 月 13 日
編集済み: John D'Errico 2017 年 5 月 13 日
What is f? Tell us CLEARLY what is f. In MATLAB terms, how is f represented? Is it symbolic? Is it a function handle?
Now, tell us what f(xi) is. Is it a scalar, double precision number, so a constant?
What is the derivative of a constant?
You cannot differentiate a constant. You CAN differentiate a function, IF it is stored in symbolic form. Then you can evaluate that result at the point xi.
So the point is, you need to understand that while you think of f as a function, it may be represented in MATLAB in several different ways. But you are the one who needs to use it and work with it.
kingsley
kingsley 2017 年 5 月 13 日
f is the function handle.

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

回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by