Calculate with initial value

1 回表示 (過去 30 日間)
Jamil Arif
Jamil Arif 2021 年 5 月 15 日
編集済み: per isakson 2021 年 6 月 2 日
i=1;
Z(i)=1;
while true
Z(i) =1 + B - q.*B.*(((Z(i))-B)./(((Z(i))-B*sigma)*((Z(i))+epsi*B)))-Z(i);
i=i+1;
end
  1 件のコメント
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 5 月 15 日
Note that in your set up "while" loop, Z(i) can't be on both sides of the equal sign. Z(i) on the left side has to be Z(i+1).

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

採用された回答

per isakson
per isakson 2021 年 5 月 16 日
There is nothing that terminates the execution of the loop when convergence is reached. Thus, the while-loop will run until the vector, Z, exceeds "Maximum possible array" or something else throws an error.
i=1;
Z(i)=1;
while true
Z(i+1) = 1 + B - q.*B.*(((Z(i))-B)./(((Z(i))-B*sigma)*((Z(i))+epsi*B)));
i = i+1;
end
Replace the loop by
tol = 1e-6;
i = 2;
Z(i) = 1;
Z(i-1) = Z(i)+2*tol;
while abs(Z(i)-Z(i-1)) >= tol
Z(i+1) = 1 + B - q.*B.*(((Z(i))-B)./(((Z(i))-B*sigma)*((Z(i))+epsi*B)));
i = i+1;
end
  2 件のコメント
Jamil Arif
Jamil Arif 2021 年 6 月 2 日
Z(i-1) = Z(i)+2*tol;
what is the function for this part of the eqn
per isakson
per isakson 2021 年 6 月 2 日
編集済み: per isakson 2021 年 6 月 2 日
The purpose of
Z(i-1) = Z(i)+2*tol;
is to make sure that
abs(Z(i)-Z(i-1)) >= tol
returns true and thus that the statements in the while-loop are executed for i equal to 2. Try to execute the code without it.

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by