How to vary an element in an equality matrix - optimisation program

Hello,
I'm running an optimisation problem using fmincon, with two equality constraints and three optimising variables x1, x2, x3. As seen in the code below, I also wish to vary the value 'lcg' which appears in the first inequality equation.
I initially tried using a for-loop (as coded below), but Matlab gives me the following error:
"In an assignment A(I) = B, the number of elements in B and I must be the same."
I understand the error, but i'm not sure how to achieve varying the value of lcg in the inequality matrix. My approach to use a for-loop was based upon my need to see all the values of x1,x2,x3 and the function for each value of lcg after the optimisation process.
If anyone could offer some advice that would be great.
Thanks, Rob
i=1
for lcg = 19:0.1:20
Aeq(i) = [(lf-lcg(i))*(bf^2)/Af, (lt-lcg(i))*(bt^2)/At, (lw-lcg(i))*(bw^2)/Aw; Aw/Af*((bf/bw)^2), Aw/At*((bt/bw)^2), 1];
beq = [(bw/Aw*(bw^2/Aw*Cm0w)+(bf^2)/Af*Cm0f); Cl];
[x fval] = fmincon(@myfun,[x1(0);x2(0)0;x3(0)],[],[],Aeq,beq,lb,ub,[],options);
i=i+1

 採用された回答

Matt J
Matt J 2013 年 4 月 21 日
編集済み: Matt J 2013 年 4 月 21 日

0 投票

N=length(lcg);
x=zeros(3,N);
fval=zeros(1,N);
for i=1:N
Aeq = [(lf-lcg(i))*(bf^2)/Af, (lt-lcg(i))*(bt^2)/At, (lw-lcg(i))*(bw^2)/Aw; Aw/Af*((bf/bw)^2), Aw/At*((bt/bw)^2), 1];
beq = [(bw/Aw*(bw^2/Aw*Cm0w)+(bf^2)/Af*Cm0f); Cl];
[x(:,i) fval(i)] = fmincon(@myfun,[x1(0); x2(0) ;x3(0)],[],[],Aeq,beq,lb,ub,[],options);
end

2 件のコメント

Matt J
Matt J 2013 年 4 月 21 日
Rob Commented:
Matt,
Many thanks, you're help is very much appreciated.
All the best,
Rob
Matt J
Matt J 2013 年 4 月 21 日
You're quite welcome.

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

その他の回答 (1 件)

Rob
Rob 2013 年 4 月 21 日
編集済み: Matt J 2013 年 4 月 21 日

0 投票

Relocated to Comment by Matt J

カテゴリ

質問済み:

Rob
2013 年 4 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by