optimization using problem based
1 view (last 30 days)
Show older comments
Hello!
i want to optimize the varibles so that i get the maximum valus of my function
i have 4 varibles (for now):
delta = optimvar('delta',1);
eta = optimvar('eta',1);
alpha = optimvar('alpha',1);
t = optimvar('t',1,'LowerBound',0,'UpperBound',Time);
and this is my constrains:
T = alpha*t^2+eta*t;
T_dot = 2*alpha*t+eta;
omega = delta*t;
%constrains
cons1 = T <= T_max;
cons2 = T >= T_min;
cons3 = omega <= omega_max;
cons4 = omega >= omega_min;
cons5 = T_dot <= T_dot_max;
cons6 = T_dot >= T_dot_min;
my questions
- how do i make my temperature profile (T) to be lower that T_max and bigger than T_min for every value of the time (0<t<Time)?
- i know i cant do it now (cause this is not a full second order profile), but if T was:
T = alpha*t^2+eta*t+const;
how can i make the sulution start from T_min? something like initial condition so that T(0) = T_min
or: how can i make the solution go trough every value between T_min and T_max?
Thank u all!
this is the full code i'm using
%% General
clc;
clear;
close;
fontsize = {'Fontsize',14};
linewidth ={'Linewidth', 1.5};
legendfont = {'FontSize' , 12};
T_max = 60;
T_min = -60;
omega_max = 200;
omega_min = -200;
T_dot_max = 5;
T_dot_min = -5;
Time = 100;
%% Optimization problem
prob = optimproblem('ObjectiveSense','max');
%optimization varibles
delta = optimvar('delta',1);
eta = optimvar('eta',1);
alpha = optimvar('alpha',1);
t = optimvar('t',1,'LowerBound',0,'UpperBound',Time);
%setting initial point
x0.delta = 0;
x0.eta = 0;
x0.t = 0;
x0.alpha = 0;
%profiles
T = alpha*t^2+eta*t;
T_dot = 2*alpha*t+eta;
omega = delta*t;
%constrains
cons1 = T <= T_max;
cons2 = T >= T_min;
cons3 = omega <= omega_max;
cons4 = omega >= omega_min;
cons5 = T_dot <= T_dot_max;
cons6 = T_dot >= T_dot_min;
prob.Constraints.cons1 = cons1;
prob.Constraints.cons2 = cons2;
prob.Constraints.cons3 = cons3;
prob.Constraints.cons4 = cons4;
prob.Constraints.cons5 = cons5;
prob.Constraints.cons6 = cons6;
%cost func
alpha = 1; %Weight factor
prob.Objective = (alpha^(2)*t^5)/5 + (alpha*eta*t^4)/2 + (delta^(2)*t^3)/3 + (eta^(2)*t^3)/3 + t;
%show and solve
show(prob)
sol = solve(prob,x0);
%% setting the profiles i get
dt = 1;
time = 0:dt:sol.t;
T_opti = sol.alpha.*time.^2+sol.eta.*time;
omega_opti = sol.delta.*time;
%% ploting
%omega profile
figure(1);
plot(time,omega_opti,linewidth{1:2});
xlabel('t [sec]');
ylabel('\omega [rad/s]');
grid on;
%temperature profile
figure(2);
plot(time,T_opti,'r',linewidth{1:2});
xlabel('t [sec]');
ylabel('T [\circC]');
grid on;
%both
figure(3);
yyaxis left
plot(time,omega_opti,linewidth{1:2});
xlabel('t [sec]');
ylabel('\omega [rad/s]');
ylim([omega_min omega_max]);
yyaxis right
grid on;
plot(time,T_opti,'r',linewidth{1:2});
xlabel('t [sec]');
ylabel('T [\circC]');
ylim([T_min T_max]);
0 Comments
Answers (1)
Matt J
on 10 Jan 2021
Are you sure t should be an optimvar? It seems to me it should be a set of discrete known values
t = linspace(0,Time,N)
Once you make that change, and choose const=T_min, it seems to me everything is as you want it.
5 Comments
Matt J
on 10 Jan 2021
well,it might be the one in the last time step, t=Time.
If so, then,
prob.Objective = (alpha^(2)*Time^5)/5 + (alpha*eta*Time^4)/2 +...
(delta^(2)*Time^3)/3 + (eta^(2)*Time^3)/3 + Time;
See Also
Categories
Find more on Problem-Based Optimization Setup 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!