Borrar filtros
Borrar filtros

how to solve the error? Error in fixed_point_3 (line 10) while iter <= max_iter

1 visualización (últimos 30 días)
function [x] = fixed_point_3(init,error,max_iter)
% 2x^3 + 4x^2 - 10 = 0 can be written as
% 4x^2 = 10 - 2x^3 --> x^2 = 1/4 *(10 - 2x^3)
% if only positive root is taken, then x = 1/4 ((10 - 2x^3)^(1/2)
%now we can use fixed point iteration
iter = 0;
now
%max_iter = maxium number of iterations
while iter <= max_iter
max_iter = 7.3814e+05;
x = (1/4)*((10- init^3)^(1/2));
iter = iter + 1;
if abs(x-init)<error
return
end
end
  2 comentarios
Matt Gaidica
Matt Gaidica el 13 de Dic. de 2020
I don't get an error passing in (1,1,1). Note: it's bad practice to use init and error as variable names, those are reserved in MATLAB. Also, use a code block to share.
function [x] = fixed_point_3(init,error,max_iter)
% 2x^3 + 4x^2 - 10 = 0 can be written as
% 4x^2 = 10 - 2x^3 --> x^2 = 1/4 *(10 - 2x^3)
% if only positive root is taken, then x = 1/4 ((10 - 2x^3)^(1/2)
%now we can use fixed point iteration
iter = 0;
now
%max_iter = maxium number of iterations
while iter <= max_iter
max_iter = 7.3814e+05;
x = (1/4)*((10- init^3)^(1/2));
iter = iter + 1;
if abs(x-init)<error
return
end
end
Walter Roberson
Walter Roberson el 13 de Dic. de 2020
??
init is used in some obscure methods such as idnlarx but it is by no means reserved.
error() is not actually reserved, but it is not a great idea to use it as a variable name.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Genetic Algorithm en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by