Problem with Modified Secant Method
5 ビュー (過去 30 日間)
古いコメントを表示
Hi, could you help me this code. The answer which is the root of the equation will always be wrong when matlab shows the value of xrc which is the value for the final iteration. Feel free to contact me if there are any questions about my code. I have a feeling that my code has some error around the part where i request the user to input the desired equation. Thanks!
clc
i=1;
x(i)=x_0;
prompt3 = 'Enter the equation in terms of x(i):';
prompt = 'Enter value of step size: ';
prompt1 = 'Enter value of first x: ';
prompt2 = 'Enter the error percentage: ';
steps = input(prompt)
x_0 = input(prompt1)
error = input(prompt2)
z = input(prompt3)
eacurrent=100;
xrc=0
ea(i)=100;
while(eacurrent>0)
F(i)= z
x(i+1)= x(i) - ((F(i)*steps)/(F(i)+steps)-F(i));
if (i>1)
ea(i)=abs((x(i+1)-x(i))/x(i+1))*100;
eacurrent=ea(i)
end
if (ea(i)>error)
i=i+1
else
xrc=x(i+1)
break
end
end
0 件のコメント
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Debugging and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!