Why it says undefined variable x2

function [x2] = secant(f, x0, x1)
while true
x2 =f(x1)*(x2-x0)/f(x0)+x1;
if x1 == x2
return;
end
x0 = x1;
x1 = x2;
end
end

Respuestas (1)

James Tursa
James Tursa el 26 de Sept. de 2018

0 votos

You have x2 appearing on the right hand side of your first assignment, before it has been defined.

3 comentarios

Dandan Lv
Dandan Lv el 26 de Sept. de 2018
thank you so much
Hazel
Hazel el 9 de Sept. de 2023
Editada: Hazel el 9 de Sept. de 2023
Hello @Dandan Lv, have you figured out this x2 equation that does not contain x2 on the RHS?
Torsten
Torsten el 9 de Sept. de 2023
Set n = 2 in the first formula on

Iniciar sesión para comentar.

Categorías

Más información sobre Get Started with MATLAB en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 26 de Sept. de 2018

Comentada:

el 9 de Sept. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by