trouble of taking derivative of function in newton method

1 次查看(过去 30 天)
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.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by