Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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 Kommentare
Matt Gaidica
Matt Gaidica am 13 Dez. 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 am 13 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by