フィルターのクリア

Minimising with multiple constraints and then storing them using a loop

1 回表示 (過去 30 日間)
econgrad
econgrad 2013 年 6 月 7 日
I want to minimize a function with two inequality constraints and different set of parameters.
min -x1*x2*x3
st
a11*x1a12*x2a13*x3 b1;
a21*x1+a22*x2+a23*x3 b2
I have 100 different A=[a11 a12 a13; a21 a22 a23] matrices and 100 different b=[b1;b2] vectors. For each pair of matrix A and vector b, I will have one solution x=(x1 x2 x3).
My goal is to have a single data set with all the solutions of all the inequality constraints. I mean the first row of that x will have the solution for 1st A,b the the 2nd row for next A,b and so on.
Can anyone please help, thank you so much.
  2 件のコメント
Matt J
Matt J 2013 年 6 月 8 日
編集済み: Matt J 2013 年 6 月 8 日
My goal is to have a single data set with all the solutions of all the inequality constraints. I mean the first row of that x will have the solution for 1st A,b the the 2nd row for next A,b and so on.
It's usually better to store things column-wise in MATLAB (as in my Answer below) since memory access is faster for columns.
econgrad
econgrad 2013 年 6 月 8 日
ok I see, thanks.

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

回答 (1 件)

Matt J
Matt J 2013 年 6 月 8 日
編集済み: Matt J 2013 年 6 月 8 日
Should be pretty straightforward. The code will look like,
X=zeros(3,100);
for i=1:100
X(:,i)=fmincon(@(x)-prod(x), InitialGuess,A(:,:,i),b(:,i));
end
  3 件のコメント
econgrad
econgrad 2013 年 6 月 8 日
編集済み: econgrad 2013 年 6 月 8 日
Matt, why do I have to use prod(x)? Also, is A(:,:,i) pick up all the rows corresponding to i th col? Sorry,in my original question I forgot to post that the A matrix I have looks like this: A=[1 2 3;2 3 4;4 1 2;1 2 4]so the first two rows will be the constraint matrix for the first problem, the next two rows for the second problem and so on. Similarly the b vector and the x0 vector are also arranged that way. I hope I have explained this properly. Thank you so much for your help.
Matt J
Matt J 2013 年 6 月 9 日
編集済み: Matt J 2013 年 6 月 9 日
why do I have to use prod(x)?
Isn't it appropriate? In the problem you posted, the objective is the product of all the variables (times -1).
Also, is A(:,:,i) pick up all the rows corresponding to i th col?
Yes, but it was just an example. Extract the linear inequality constraint data for the i-th problem in whatever way suits the way you have your data organized.

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

カテゴリ

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