Problem with Modified Secant Method
5 views (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on Debugging and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!