Constrained Optimisation in MATLAB

2 views (last 30 days)
Karthick Jonagadla
Karthick Jonagadla on 24 May 2016
Commented: Bjorn Gustavsson on 24 May 2016
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 Comments
Torsten
Torsten on 24 May 2016
But you multiply transpose(B)*A with A, which gives a (1x15) vector.
Best wishes
Torsten.
Karthick Jonagadla
Karthick Jonagadla on 24 May 2016
Edited: Karthick Jonagadla on 24 May 2016
I had attached the sample code for your reference so that it clears the confusion

Sign in to comment.

Answers (3)

Bjorn Gustavsson
Bjorn Gustavsson on 24 May 2016
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 on 24 May 2016
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 Comment
Karthick Jonagadla
Karthick Jonagadla on 24 May 2016
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?

Sign in to comment.


Bjorn Gustavsson
Bjorn Gustavsson on 24 May 2016
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 Comments
Karthick Jonagadla
Karthick Jonagadla on 24 May 2016
Edited: Karthick Jonagadla on 24 May 2016
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 on 24 May 2016
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

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!