필터 지우기
필터 지우기

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 CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by