What's wrong whith my schedule ?

1 回表示 (過去 30 日間)
Ainadou Eude
Ainadou Eude 2021 年 4 月 23 日
回答済み: Les Beckham 2021 年 4 月 23 日
clear all;
close all;
clc;
E=0;
while E~=0,2
Io=45.4746;
I=(2*Io)+4;
E=(I-Io)/Io;
G=(Io+E);
Io=G;
end

回答 (1 件)

Les Beckham
Les Beckham 2021 年 4 月 23 日
There are several things wrong with this code.
First
while E~=0,2
is not valid Matlab syntax. Replace the , with a . if you mean to test for 0.2 (i.e., 1/5).
Second, you are resetting Io at the beginning of each loop so you will get the same results on every pass through the loop. Move the line
Io=45.4746;
above the while loop.
Third, this algorithm (if you move the initialization of Io outside the loop), converges to 1.0 and will never reach 0.2. So, you have an infinite loop.

カテゴリ

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