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
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 Center 및 File Exchange에서 Calculus에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!