フィルターのクリア

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

2 ビュー (過去 30 日間)
SARMILADEVI BHASKARAN
SARMILADEVI BHASKARAN 2020 年 12 月 13 日
コメント済み: Walter Roberson 2020 年 12 月 13 日
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 件のコメント
Matt Gaidica
Matt Gaidica 2020 年 12 月 13 日
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 2020 年 12 月 13 日
??
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.

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeGenetic Algorithm についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by