Constrained Optimisation in MATLAB

2 ビュー (過去 30 日間)
Karthick Jonagadla
Karthick Jonagadla 2016 年 5 月 24 日
コメント済み: Bjorn Gustavsson 2016 年 5 月 24 日
I have a 11x11 matrix A with set of values.I have an another 11x1 matrix B with set of values
Resultant, C=(transpose(B)*A)* A; D= 30/C;
My objective function is to maximize D by changing the values of Matrix B subject to the following constraints 1) The values of 11x1, Matrix B should be between upper and lower bound The matrix B is imagined to be split into upper half of 7 elements and lower half of 4 elements 2) The number of elements whose value changes in the upper half of matrix B should be less than or equal to 3 3) The number of elements whose value changes in the lower half of matrix B should be less than or equal to 2
I have attached the script for your reference. fun1 is the function which has a output D and I want to maximize D. Script is the script which I coded
Experts, I need some help on this. Thanks in advance.
  6 件のコメント
Torsten
Torsten 2016 年 5 月 24 日
But you multiply transpose(B)*A with A, which gives a (1x15) vector.
Best wishes
Torsten.
Karthick Jonagadla
Karthick Jonagadla 2016 年 5 月 24 日
編集済み: Karthick Jonagadla 2016 年 5 月 24 日
I had attached the sample code for your reference so that it clears the confusion

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

回答 (3 件)

Bjorn Gustavsson
Bjorn Gustavsson 2016 年 5 月 24 日
Have a look at
fmincon
or if you don't have the optimization toolbox, you can find several useful entries at the file exchange. Look for the fminsearchbnd and minimize submissions
HTH

Torsten
Torsten 2016 年 5 月 24 日
Conditions 2 and 3 give (7C3)*(4C2)=210 cases to be considered. (nCk = n!/(k!*(n-k)!)
I think the easiest way would be to use fmincon to calculate these 210 cases and to extract the one with largest value of the objective.
Best wishes
Torsten.
  1 件のコメント
Karthick Jonagadla
Karthick Jonagadla 2016 年 5 月 24 日
I had been working on this problem for long and couldn't find any solution. Could you give me a sample code where which covers at least 2 to 3 iterations?

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


Bjorn Gustavsson
Bjorn Gustavsson 2016 年 5 月 24 日
It seems your source code is different again from what you seem to want to do.
I'll assume that the problem you want to solve is this:
% min(C) where C is
C = (transpose(B)*A)*B; % this at least makes C scalar
B0 = ones(11,1);
fcn = @(B) (transpose(B)*A)*B;
UB = [ones(7,1)*3;ones(4,1)*2];
Boptimal = fmincon(fcn,B0,eye(length(B)),UB);
HTH
  2 件のコメント
Karthick Jonagadla
Karthick Jonagadla 2016 年 5 月 24 日
編集済み: Karthick Jonagadla 2016 年 5 月 24 日
Hi Bjorn,
You got my question wrong 1)I had introduced D which is 30/C.I need to maximize D 2)The number of elements whose value changes in the upper half of matrix B should be less than or equal to 3. I am not referring to the bounds 3) The number of elements whose value changes in the lower half of matrix B should be less than or equal to 2. Again, I am not referring to the bounds
To put it simple. I need a constraint which will change values of only a certain number of elements, lets say 3 or 4 values in a vector [Nx1]. In this case it is the matrix B
I have attached the sample code in the main question
Bjorn Gustavsson
Bjorn Gustavsson 2016 年 5 月 24 日
Well your problem is at least in one other place...
The equation for C in your original question gives a 1x11 array. Which makes your equation for D less than desirably suitable for optimization. That expression does not agree with your fun1.m. When I run that with the following input I get some errors. Your first effort should be to make that one work...
type fun1
function [D] = fun1(A,B)
C = (transpose(A)*B)* A;
C = sqrt(C);
D = (30)/C;
D = -1*D;
>> A = randn(11);
>> B = rand(11,1);
>> D = fun1(A,B)
Error using *
Inner matrix dimensions must agree.
Error in fun1 (line 2)
C = (transpose(A)*B)* A;
>> D = fun1(A,B.')
Error using *
Inner matrix dimensions must agree.
Error in fun1 (line 2)
C = (transpose(A)*B)* A;
>> C=(transpose(B)*A)* A; D= 30/C;
Error using /
Matrix dimensions must agree.
Now looking into your script it seems that you
1, call the function with the inputs from your description swapped.
2, In your definition of the function you optimize you don't use the weights input parameter.
You'll get some output by changing the script to:
f = @(W) fun1(W,C);
[Out1,Out2,Out3]= fmincon(f,R,A,B,Aeq,Beq,ILB,IUB,[],options);
Hopefully that is a solution to your problem.
HTH

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

カテゴリ

Help Center および File ExchangeSurrogate Optimization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by