Optimization of vectors with optimization toolbox

6 views (last 30 days)
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:
  1. i would like to add 2 more constrains, about domega/dt and for dT/dt. any one have idea how to do that?
  2. when i try to solve this problem, i get :The problem is non-convex. how sould i continue?
  3. 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
eden meirovich
eden meirovich on 21 Dec 2020
i know the solution (i try to max the trace and the det, not minimize).
i just want to get this "easy" one, before i continue to one i don't know

Sign in to comment.

Answers (1)

Matt J
Matt J on 21 Dec 2020
Edited: Matt J on 21 Dec 2020
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);

Community Treasure Hunt

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

Start Hunting!