Secant method Nan Error

1 visualización (últimos 30 días)
Grégoire
Grégoire el 14 de Mzo. de 2024
Comentada: Grégoire el 14 de Mzo. de 2024
hey,
I'm trying to learn how to code the Secant Method,
I think I am getting everything right but the values of my variables are 'NaN'... what does it mean and how can I change it ?
Thanks for the help !
R=3;
f= @(x) (pi.*(x.^2)).*(3.*R-x)-3.*48.25;
X0=2;
X1=3;
Y0= f(X0);
Y1= f(X1);
k=1;
error=1;
while k<10 && error>10^(-6)
X = X1 - (X0-X1).*Y1./(Y0-Y1) ;
Y = f(x);
X0=X1;
X1=X;
Y0=Y1;
Y1=Y;
k =k+1;
end
X
Y

Respuesta aceptada

Alan Stevens
Alan Stevens el 14 de Mzo. de 2024
You haven't updated error in your while loop. Try including something like
error = abs(X0-X1);
  1 comentario
Grégoire
Grégoire el 14 de Mzo. de 2024
Perfect ! thanks for the help :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by