Correct formulation for a fmincon problem

4 vues (au cours des 30 derniers jours)
Tiziano Refice
Tiziano Refice le 15 Mar 2019
Commenté : Torsten le 15 Mar 2019
Good morning!
As the title says, I'm trying to solve an optimal control problem: given a paper on employment, my goal for now is to replicate the results of the paper. Briefly, I have:
  • five variable functions (U(t), T(t), R(t), V1(t) and V2(t))
  • four control functions(u1(t), u2(t), u3(t), u4(t))
  • constraints on the control variables (each u must be between 0 and 1)
  • initial values for U, T, R, V1 and V2 (in t=0, in particular V1 and V2 are constant over time)
  • final values for the λ coefficients in the hamiltonian
As you can see, both variable and control functions are time dependent.
I don't think that this can be useful for the question, but for completeness, I'm putting also my starting model:
%I've neglected the time dependency to quickly write the system
dU = delta - (1 + u1)*k1*U*V1 - (1 + u2)*k2*U*V2 - alpha1*U + gamma1*T + gamma2*R;
dT = (1 + u1)*k1*U*V1 - k3*T*V2 - alpha2*T - gamma1*T;
dR = (1 + u2)*k2*U*V2 - alpha3*R - gamma2*R + k3*T*V2;
dV1 = alpha2*T + gamma1*T + (1 + u3)*phi1*U + k3*T*V2 - delta1*V1;
dV2 = alpha3*R + gamma2*R + (1 + u4)*phi2*U - delta2*V2;
All the other values that you see in there are numerical parameters for which I have a given value (k1, alpha1, etc.).
Following my professor's suggestions, I'm using the fmincon function,that can avoid me to do all the necessary calculations to solve this kind of problem (costate equations etc.), and it seems to be a suitable way to solve the problem. Without going in the details, here's a brief explenation of the situation:
I have to find an optimal solution for a cost function, that has dipendency in four control variables and in one other function, for which I have not the expression.
f = A1*U(t) + (A2/2)*(u1(t))^2 + (A3/2)*(u2(t))^2 + (A4/2)*(u3(t))^2 + (A5/2)*(u4(t))^2; % U is the "other" function mentioned above
Here is where I'm stucked. I can't find a good way to set the problem using fmincon.
The main problem is that, using multiple control/variable functions, I have to order them in an array, and in this way my indices are used to point the position of the control functions in the array and so the time dependency can't be indicated. In fact, the only way that gave me a result, is this one:
syms U u
% Here f is named g, but nothing changes, it's just taken from an older file
g = @(u) 30*u(5) + (20/2)*(u(1))^2 + (20/2)*(u(2))^2 + (10/2)*(u(3))^2 + (40/2)*(u(4))^2; % U has become u(5) in order to be evaluated together with the controls
%initial guesses
u0 = [0, 0, 0, 0, 100000]; %I'm sure that this is an error, because the last number should be an initial value(U(t=0)=100000)
A = []; %for this first try, I'm not using any costate equation
b = [];
Aeq = [];
beq = [];
lb = 0.0 * ones(1,2,3,4);
ub = 1.0 * ones(1,2,3,4);
[x,fval,output,lambda] = fmincon(g, u0, A, b, Aeq, beq, lb, ub);
In this case, fmincon return (obviously) one value for each function in g:
x =
1.0e-03 *
0.3168 0.3168 0.4493 0.2254 0.0001
Summarizing, my questions are:
  • Is there a better way to set up my problem? (I'm working on this, starting with the creation of the .m file for the function, but some advices are welcome)
  • how can I specify the dependency on time?
  • Since I have also the costate equations, and the final values of the lambdas are 0 (λi(t=10)=0, I have one λ for each variable in the problem), is it useful to use them too or it's unnecessary? (maybe in a const.m file or similar)
Since I'm new on matlab, I might not have explained it well, so any question is welcome.
Thank you so muche in advance.

Réponses (1)

Torsten
Torsten le 15 Mar 2019
The vector of unknowns for fmincon will be
Uvec = [u1(t0),u2(t0),u3(t0),u4(t0),u5(t0),u1(t2),u2(t2),u3(t2),u4(t2),u5(t2),...,u1(tend),u2(tend),u3(tend),u4(ten),u5(tend)]
and the objective function you want to minimize will be some kind of integral in which the discrete values ui(t1),ui(t2),...,ui(tend) are used to approximate this integral (e.g. via the trapezoidal rule).
I think you are not the first person who uses fmincon to solve a control problem. So before naively trying to code something, I'd first search the web for similar contributions.
  2 commentaires
Tiziano Refice
Tiziano Refice le 15 Mar 2019
Thank you for the answer!
Yes, I've tried to search for something similar, and the code I provided comes from the basic tutorials of mathworks. I've also tried to change things looking at some other topic here on Matlab answers. But the results were not satisfactory at all, maybe even because I'm not so clever using matlab (this is the first time I use it for this kind of stuff).
Torsten
Torsten le 15 Mar 2019
https://www.google.de/search?source=hp&ei=24uLXMCfB8TjsAfbirGgCQ&q=matlab+%26+optimal+control+problem&btnK=Google-Suche&oq=matlab+%26+optimal+control+problem&gs_l=psy-ab.3..0i22i30l9.652.8151..8518...0.0..0.148.1726.31j1......0....1..gws-wiz.....0..0i131j0j0i10j0i22i10i30j0i13i30j0i13i5i30j0i8i13i30.wjTvlsVZ-lw

Connectez-vous pour commenter.

Catégories

En savoir plus sur Introduction to Installation and Licensing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by