Effacer les filtres
Effacer les filtres

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.

3 vues (au cours des 30 derniers jours)
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

Réponse acceptée

KSSV
KSSV le 22 Fév 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.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by