Constrained Optimisation in MATLAB
2 次查看(过去 30 天)
显示 更早的评论
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
2016-5-24
But you multiply transpose(B)*A with A, which gives a (1x15) vector.
Best wishes
Torsten.
回答(3 个)
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
0 个评论
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.
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 个评论
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 Exchange 中查找有关 Surrogate Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!