필터 지우기
필터 지우기

Resolve a Complex equation in a loop WHILE

조회 수: 1 (최근 30일)
Eduardo
Eduardo 2014년 4월 13일
답변: Alberto 2014년 4월 14일
Hello,
I am trying to resolve a Newton-Raphson method by a complex equation.
But I am with the following error:
Attempted to access f(2.07279); index must be a positive integer or logical.
Error in teste04 (line 17) x = (x - (f(x)/df(x)));
I wrote the code:
x=2; %initial value
x_old= 12;
% c = 1.1 % If c is greater than the unity all the roots will be complex
c = 0.99; % If c is lower than the unity all the roots will be real
f(x)=(1-((c*x/2)*(log(x+1)-log(x-1)))); % the function that I would like to calculate the root by the newton-raphson method
df(x)=((c/2)*((log(x+1)-log(x-1))+(2*x/(x^2-1)))); % derivative of the f(x)
tolerance=0.00001; % the method will stop if the difference between the the diff = [x(i+1) - x(i)] were lower than 1E-5
while abs(x_old-x) > tolerance
x_old = x;
x = (x - (f(x)/df(x)));
pause;
end

답변 (1개)

Alberto
Alberto 2014년 4월 14일
I think you defined your functions badly. Try something like
f=@(x)(1-((c*x/2)*(log(x+1)-log(x-1))))

카테고리

Help CenterFile Exchange에서 Newton-Raphson Method에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by