Problem with Modified Secant Method

4 Ansichten (letzte 30 Tage)
Daniel Lau
Daniel Lau am 16 Mai 2016
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

Antworten (0)

Kategorien

Mehr zu Debugging and Analysis finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by