optimization problem - problem using det funciton

1 Ansicht (letzte 30 Tage)
eden meirovich
eden meirovich am 19 Sep. 2021
Kommentiert: eden meirovich am 21 Sep. 2021
Hello
i'm trying to solve an optimization problem with involve calcualte the det of a matrix (here it's the temp varible).
the temp operator work for me before with optimization varibles, but now there is a problem. i think it's involve with using a non-linear optimization varibles, such as the varible F.
the error i get:
Check for missing argument or incorrect argument data type in call to function 'det'.
Error in optimization_vector_form (line 82)
prob.Objective = det(temp);
any ideas?
Thank you
clc;
clear;
close all;
Time = 100;
dt=1;
N=Time/dt;
%% Optimization problem
prob = optimproblem('ObjectiveSense','max');
%optimization varibles
omega = optimvar('omega',N,'LowerBound',w_min,'UpperBound',w_max);
T = optimvar('T',N,'LowerBound',T_min,'UpperBound',T_max);
%% Constrains
for i=1:N-1
cons1(i) = (T(i+1)-T(i))/dt >= T_dot_min;
cons2(i) = (T(i+1)-T(i))/dt <= T_dot_max;
cons3(i) = (omega(i+1)-omega(i))/dt >= omega_dot_min;
cons4(i) = (omega(i+1)-omega(i))/dt <= omega_dot_max;
end
prob.Constraints.cons1 = cons1;
prob.Constraints.cons2 = cons2;
prob.Constraints.cons3 = cons3;
prob.Constraints.cons4 = cons4;
for i=1:N-1
A(i) = omega(i)^2;
B(i) = T(i)^2;
C(i) = omega(i)*T(i);
F(i) = omega(i)^2*T(i);
G(i) = omega(i)*T(i)^2;
H(i) = omega(i)^2*T(i)^2;
end
D = sum(omega);
E = sum(T);
temp = [A.sum F.sum D C.sum;
F.sum H.sum C.sum G.sum;
D C.sum Time E;
C.sum G.sum E B.sum];
prob.Objective = det(temp);

Akzeptierte Antwort

Alan Weiss
Alan Weiss am 20 Sep. 2021
The main problem is that det is not a Supported Operations on Optimization Variables and Expressions. For example,
x = optimvar('x',2,2);
y = det(x)
Check for incorrect argument data type or missing argument in call to function 'det'.
You should also learn to make more efficient optimization expressions. I rewrote some of your expressions using an indexing technique that enables vectorized addition and subtraction, removing your inefficient loops.
Time = 100;
dt = 1;
N = Time/dt;
w_min = 0; % I made up constants to get this to work
w_max = 10; % Put in your own constants
T_min = 1;
T_max = 100;
T_dot_min = -10;
T_dot_max = 10;
omega_dot_min = -1;
omega_dot_max = 1;
%% Optimization problem
prob = optimproblem('ObjectiveSense','max');
%optimization varibles
omega = optimvar('omega',N,'LowerBound',w_min,'UpperBound',w_max);
T = optimvar('T',N,'LowerBound',T_min,'UpperBound',T_max);
indces = 1:(N - 1); % This is the technique
%% Constrains
% for i=1:N-1
% cons1(i) = (T(i+1)-T(i))/dt >= T_dot_min;
% cons2(i) = (T(i+1)-T(i))/dt <= T_dot_max;
% cons3(i) = (omega(i+1)-omega(i))/dt >= omega_dot_min;
% cons4(i) = (omega(i+1)-omega(i))/dt <= omega_dot_max;
% end
cons1 = (T(indces + 1) - T(indces))/dt >= T_dot_min;
cons2 = (T(indces + 1) - T(indces))/dt <= T_dot_max;
cons3 = (omega(indces + 1) - omega(indces))/dt >= omega_dot_min;
cons4 = (omega(indces + 1) - omega(indces))/dt <= omega_dot_max;
prob.Constraints.cons1 = cons1;
prob.Constraints.cons2 = cons2;
prob.Constraints.cons3 = cons3;
prob.Constraints.cons4 = cons4;
% I also use indces here
% for i=1:N-1
% A(i) = omega(i)^2;
% B(i) = T(i)^2;
% C(i) = omega(i)*T(i);
% F(i) = omega(i)^2*T(i);
% G(i) = omega(i)*T(i)^2;
% H(i) = omega(i)^2*T(i)^2;
% end
A = omega(indces).^2;
B = T(indces).^2;
C = omega(indces).*T(indces);
F = (omega(indces).^2).*T(indces);
G = omega(indces).*(T(indces).^2);
H = omega(indces).^2.*(T(indces).^2);
D = sum(omega(indces));
E = sum(T(indces));
temp = [A.sum F.sum D C.sum;
F.sum H.sum C.sum G.sum;
D C.sum Time E;
C.sum G.sum E B.sum];
To use the unsupportetd operation det, use fcn2optimexpr.
detexpr = fcn2optimexpr(@det,temp);
prob.Objective = detexpr;
Alan Weiss
MATLAB mathematical toolbox documentation

Weitere Antworten (0)

Kategorien

Mehr zu Problem-Based Optimization Setup finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by