필터 지우기
필터 지우기

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 (최근 30일)
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

채택된 답변

KSSV
KSSV 2023년 2월 22일
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개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by