Optimization of vectors with optimization toolbox
Show older comments
hello, new to optimization toolbox here :)
i wolud like to optimize 2 vectors:
omega (100X1)
T (100X1)
i have 2 constrains on this vectors
-200<omega>200
-60<T<60
H it's a matrix equal to :H = [omega 1 T]
and M = transpose(H)* H;
i wrote my M matrix result alredy.
my code look like this:
omega = optimvar('omega',100,'LowerBound',-200,'UpperBound',200);
T = optimvar('Temperature',100,'LowerBound',-60,'UpperBound',60);
t = transpose(0:1:100-1);
M = [sum(omega.*omega) sum(omega) sum(omega.*T) ; ...
sum(omega) sum(ones(length(omega),1)) sum(T) ;
sum(omega.*T) sum(T) sum(T.*T) ];
i want to optimize omega and T with this two objective functions
1.trace(M)
2.Det(M)
J1 = trace(M);
J2 = det(M);
prob = optimproblem("ObjectiveSense",'maximize');
prob.Objective =J1;
sol = solve(prob)
my questions:
- i would like to add 2 more constrains, about domega/dt and for dT/dt. any one have idea how to do that?
- when i try to solve this problem, i get :The problem is non-convex. how sould i continue?
- when i try to calculate det(M) i get this error : Check for missing argument or incorrect argument data type in call to function 'det'. can i even use this function with optimization varible ?
7 Comments
Walter Roberson
on 21 Dec 2020
No, det() is not defined for optimvar .
Fortunately you have a 3 x 3 system so you can construct the determinant
M1_1 = sum(omega.^2)
M1_2 = sum(omega)
M1_3 = sum(omega.*T)
and so on
detM = M1_1*M2_2*M3_3 - M1_1*M2_3*M3_2 - M1_2*M2_1*M3_3 + M1_2*M2_3*M3_1 + M1_3*M2_1*M3_2 - M1_3*M2_2*M3_1
eden meirovich
on 21 Dec 2020
Bruno Luong
on 21 Dec 2020
Edited: Bruno Luong
on 21 Dec 2020
Use solver based rather than problem based.
BTW I can't see t is used anywhere.
You might revise how you formulate the optimization problem.
eden meirovich
on 21 Dec 2020
i want to optimize omega and T with this two objective functions...
The solutions are trivially omega=T=zeros(100,1) for both objective functions, unless the constraints on the derivatives that you intend to impose bound at least some of the derivatves strictly away from zero.
Bruno Luong
on 21 Dec 2020
FMINCON?
eden meirovich
on 21 Dec 2020
Answers (1)
i would like to add 2 more constrains, about domega/dt and for dT/dt. any one have idea how to do that?
You can use diff() to implement constraints on numerical derivatives, e.g.,
omega = optimvar('omega',100,'LowerBound',-200,'UpperBound',200);
T = optimvar('Temperature',100,'LowerBound',-60,'UpperBound',60);
domega=diff(omega); %derivatives
dT=diff(T);
C.con_domega=lower_domega<=domega & domega<=upper_domega; %bounds on derivatives
C.con_dT=lower_dT<=dT & dT<=upper_dT
As long as all these constraints are linear, you can then use prob2matrices,
to assist in the conversion from the problem-based to the solver-based framework. E.g.,
sol0.omega=omega0; %initial guesses
sol0.T=T0;
prob=prob2matrices({omega,T},'Constraints',C,'sol0',sol0);
prob.x0=reshape(prob.x0,[],2);
prob.solver='fmincon';
prob.fun=@(x) sum(x.^2,'all'); %equivalent to trace M
x1=fmincon(prob);
e = ones(length(omega),1);
prob.fun=@(x) det([x,e].' * [x,e]);
x2=fmincon(prob);
Categories
Find more on Choose a Solver in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!