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:
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;
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
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;
u0 = [0, 0, 0, 0, 100000];
A = ;
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:
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.