Resolve a Complex equation in a loop WHILE
2 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (1 件)
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))))
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!