question about the using of the loop function

1 回表示 (過去 30 日間)
Amr Sadek
Amr Sadek 2014 年 6 月 7 日
コメント済み: Star Strider 2014 年 6 月 7 日
Hello, How can I use the final results obtained from the first iteration of a loop function in the second iteration of the same loop? For example, let T=[100:200], and A(T0) and k are constant known values. for T=T1, I want to calculate the following: I(T1)=A(T0).* exp(T1)
A(T1)=I(T1).* k
However, for T=T2, I want to calculate:
I(T2)= A(T1).* exp(T2)
A(T2)=I(T2).*k
and,
fot T=T3,
I(T3)= A(T2).* exp(T3)....and so on.
A(T3)=I(T3) Thanks

採用された回答

Star Strider
Star Strider 2014 年 6 月 7 日
With T that large, you quickly end up with an array of Inf values.
This loop will do what you want:
A0 = 3;
k = 5;
I(1) = A0 * exp(100);
A(1) = I(1)*k;
for T = 2:100
I(T)= A(T-1).* exp(T+99);
A(T) = I(T)*k;
end
I started the loop counter at 1 rather than 100 because otherwise your arrays are padded with 99 zeros. That takes up memory.
  2 件のコメント
Amr Sadek
Amr Sadek 2014 年 6 月 7 日
Thank you. This is exactly what I want. I will try to apply it now on my real equations.
Star Strider
Star Strider 2014 年 6 月 7 日
My pleasure!
(The sincerest form of appreciation here on MATLAB Answers is to Accept the Answer that most closely solves your problem.)

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

その他の回答 (0 件)

カテゴリ

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