Can anyone tell me why I'm getting an error here? "xold=xnew;'' is giving me an error in this statement and I'm not sure why.
4 views (last 30 days)
Show older comments
clear all
close all
clc
% Problem 6.7
while (1)
fx=@(x) x.^3-6*x.^2+11*x-6.1;
% Using the Modified Secant Method
xold=3.5;
d=0.01;
% Iteration 1
xold=xnew;
xnew=xold-d*xold*fx(xold)/(fx(xold+d*xold)-fx(xold));
ea=abs((xnew-xold)/xnew)*100;
% Iteration 2
xold=xnew;
xnew=xold-d*xold*fx(xold)/(fx(xold+d*xold)-fx(xold));
ea=abs((xnew-xold)/xnew)*100;
% Iteration 3
xold=xnew;
xnew=xold-d*xold*fx(xold)/(fx(xold+d*xold)-fx(xold));
ea=abs((xnew-xold)/xnew)*100;
fprintf('The root using 3 iterations of Modified Secant Method is %8.4f with an approximate relative error of %6.3e\n',xnew,ea)
end
Accepted Answer
KSSV
on 22 Feb 2023
These lines:
xold=3.5;
d=0.01;
% Iteration 1
xold=xnew;
xnew=xold-d*xold*fx(xold)/(fx(xold+d*xold)-fx(xold));
will obviously thrwo an error becuase xnew is a new variable and it is not defined. You need to either comment this line or you may need to move to the next line. After calculating xnew then save xnew to xold.
0 Comments
More Answers (0)
See Also
Categories
Find more on MATLAB Mobile Fundamentals 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!