optimization using solver based

2 visualizzazioni (ultimi 30 giorni)
eden meirovich
eden meirovich il 13 Gen 2021
Commentato: Alan Weiss il 19 Gen 2021
hello!
i'm trying to use optimization tool box (problem based), and optimize 2 vector NX1 data potints.
omega = optimvar('omega',N,'LowerBound',omega_min,'UpperBound',omega_max);
T = optimvar('T',N,'LowerBound',T_min,'UpperBound',T_max);
i have my constrains here on the lower bound and upper bound, and i have constrain on thegradient too:
%% 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;
and my cost function here.
one = ones(N,1);
prob.Objective = sum(omega(:).*omega(:))+sum(one)+sum(T(:).*T(:));
%show and solve
%show(prob)
x0.omega(1:N)=0;
x0.T(1:N) =0;
sol = solve(prob,x0);
disp(sol);
when i run the code i get that: The problem is non-convex.
any idea what can i do to solve it?
full code:
%% General
clc;
clear;
close;
fontsize = {'Fontsize',14};
linewidth ={'Linewidth', 1.5};
legendfont = {'FontSize' , 12};
axissize = {'FontSize' , 12};
T_max = 60;
T_min = -60;
omega_max = 200;
omega_min = -200;
T_dot_max = 5;
T_dot_min = -5;
omega_dot_max = 10;
omega_dot_min = -10;
Time = 100;
dt=1;
N=100;
%% Optimization problem
prob = optimproblem('ObjectiveSense','max');
%optimization varibles - change here
omega = optimvar('omega',N,'LowerBound',omega_min,'UpperBound',omega_max);
T = optimvar('T',N,'LowerBound',T_min,'UpperBound',T_max);
%t = optimvar('t',1,'LowerBound',0,'UpperBound',Time);
t = 0:dt:Time;
%setting initial point - change here
x0.T =0 ;
x0.omega = 0;
%% 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;
%initial condition
cons7 = T(1)==-60;
prob.Constraints.cons7=cons7;
cons8 = omega(1)==0;
prob.Constraints.cons8=cons8;
%cost func
%w =10^-12 ;%Weight factor
one = ones(N,1);
prob.Objective = sum(omega(:).*omega(:))+sum(one)+sum(T(:).*T(:));
%show and solve
%show(prob)
x0.omega(1:N)=0;
x0.T(1:N) =0;
sol = solve(prob,x0);
disp(sol);

Risposte (1)

Alan Weiss
Alan Weiss il 18 Gen 2021
Try adding the following lines after your script has run:
options = optimoptions('fmincon','MaxIterations',1e4);
[sol,fval,exitflag,output] = solve(prob,x0,'Solver','fmincon','Options',options);
Alan Weiss
MATLAB mathematical toolbox documentation
  2 Commenti
eden meirovich
eden meirovich il 19 Gen 2021
first off all thank u.
this do helping me (i increasd it even more) to get a solution, but it's looks like it's not the the corect one. i even plot the cost function over time, and it's not getting bigger over time.
any other tips?
Eden,
Alan Weiss
Alan Weiss il 19 Gen 2021
You can try different starting points. See Change the Initial Point and Local vs. Global Optima.
Alan Weiss
MATLAB mathematical toolbox documentation

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by