Problem with Modified Secant Method

조회 수: 2 (최근 30일)
Daniel Lau
Daniel Lau 2016년 5월 16일
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개)

카테고리

Help CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by