Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
SARMILADEVI BHASKARAN
SARMILADEVI BHASKARAN le 13 Déc 2020
Commenté : Walter Roberson le 13 Déc 2020
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 commentaires
Matt Gaidica
Matt Gaidica le 13 Déc 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 le 13 Déc 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.

Connectez-vous pour commenter.

Réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by