フィルターのクリア

Running a while loop in a for loop

2 ビュー (過去 30 日間)
m13
m13 2016 年 2 月 15 日
回答済み: Image Analyst 2016 年 2 月 16 日
I am trying to solve multiple equations for different times until the last equation equals a certain value. Something like this:
for t1=0:10
v1=a*b*t1
G=v1/t1
v2=v1-p1/G
t2=v2/G
x=G*t2*a
end
until x=100.
a,b and p1 are all defined outside the for loop. Is there a way to solve this in Matlab?

回答 (2 件)

Stalin Samuel
Stalin Samuel 2016 年 2 月 15 日
t1 = 0;
while(x~=100)
v1=a*b*t1;
G=v1/t1;
v2=v1-p1/G;
t2=v2/G;
x=G*t2*a;
t1=t1+1;
end

Image Analyst
Image Analyst 2016 年 2 月 16 日
Try this:
% Make up some values.
a=2
b=3
p1=5
% Now start the loop, breaking if x >= 100.
for t1=0:10
v1=a*b*t1;
G=v1/t1;
v2=v1-p1/G;
t2=v2/G;
x=G*t2*a;
fprintf('For t1 = %d, x = %.2f\n', t1, x);
if x >= 100
break;
end
end

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by