trouble of taking derivative of function in newton method

1 vue (au cours des 30 derniers jours)
kingsley
kingsley le 13 Mai 2017
Modifié(e) : kingsley le 13 Mai 2017
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 commentaires
John D'Errico
John D'Errico le 13 Mai 2017
Modifié(e) : John D'Errico le 13 Mai 2017
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 le 13 Mai 2017
f is the function handle.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by