フィルターのクリア

How to make loop and sum the result ??

4 ビュー (過去 30 日間)
ali
ali 2014 年 6 月 4 日
コメント済み: Mahdi 2014 年 6 月 4 日
I have this loop...
for i=1:3
A=x((i-1)*3+1);
B=x((i-1)*3+2);
C=x((i-1)*3+3);
R=A^2+B^3+A*c;
end
i have constriants D=7 or <7
so i need this costraint=D-C-M
let say M=2
my equestion is how can i have the sumuation result of C from loop three times and then add this sum to constraint equation???
Thank you.

採用された回答

Mahdi
Mahdi 2014 年 6 月 4 日
for i=1:3
A(i)=x((i-1)*3+1);
B(i)=x((i-1)*3+2);
C(i)=x((i-1)*3+3);
R(i)=A^2+B^3+A*c;
end
Summation=sum(C);

その他の回答 (1 件)

ali
ali 2014 年 6 月 4 日
Thank you Mahdi for answer, but i want the result value of c in each loop after sum add to eq .. constraint =D-C( sum of result in each loop)- M
  1 件のコメント
Mahdi
Mahdi 2014 年 6 月 4 日
Just move the summation inside the for loop:
for i=1:3
A(i)=x((i-1)*3+1);
B(i)=x((i-1)*3+2);
C(i)=x((i-1)*3+3);
R(i)=A^2+B^3+A*c;
Summation(i)=sum(C);
end
In this case, each row of summation would correspond to the summation inside each iteration of the loop.

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

カテゴリ

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