optimization using problem based

조회 수: 2 (최근 30일)
eden meirovich
eden meirovich 2021년 1월 10일
댓글: eden meirovich 2021년 1월 12일
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
  1. 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)?
  2. 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]);

답변 (1개)

Matt J
Matt J 2021년 1월 10일
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
Matt J
Matt J 2021년 1월 10일
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;
eden meirovich
eden meirovich 2021년 1월 12일
thank u for the answer!
i have another question about this problem.
if i wish to make my temperature profile (T) go through all th range ( so go bewteen -60 to 60). how can i add this?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Video games에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by