MATLAB: Optimization fmincon with integral. Results not optimal, what am I doing wrong

fminconintegraloptimizationOptimization Toolbox

Hi, I have the following parameterization of x,y and z
with N = 4
Then I have three forces defined as: (Clohessy-Wiltshire equations..)
and I'm trying to minimise the following cost function
which I have included in MATLAB as
% x,y,z and derivatives
x = @(t,c) c(1) + c(2)*t + c(3)*t.^2 + c(4)*t.^3 + c(5)*t.^4;
y = @(t,c) c(6) + c(7)*t + c(8)*t.^2 + c(9)*t.^3 + c(10)*t.^4;
z = @(t,c) c(11) + c(12)*t + c(13)*t.^2 + c(14)*t.^3 + c(15)*t.^4;
xDot = @(t,c) c(2) + 2*c(3)*t + 3*c(4)*t.^2 + 4*c(5)*t.^3;
yDot = @(t,c) c(7) + 2*c(8)*t + 3*c(9)*t.^2 + 4*c(10)*t.^3;
zDot = @(t,c) c(12) + 2*c(13)*t + 3*c(14)*t.^2 + 4*c(15)*t.^3;
xDdot = @(t,c) 2*c(3) + 6*c(4)*t + 12*c(5)*t.^2;
yDdot = @(t,c) 2*c(8) + 6*c(9)*t + 12*c(10)*t.^2;
zDdot = @(t,c) 2*c(13) + 6*c(14)*t + 12*c(15)*t.^2;
% forces definition
uX = @(t,c) xDdot(t,c) - 3*(nOrbit^2)*x(t,c) - 2*nOrbit*yDot(t,c);
uY = @(t,c) yDdot(t,c) + 2*nOrbit*xDot(t,c);
uZ = @(t,c) zDdot(t,c) + (nOrbit^2)*z(t,c);
% cost function
fun = @(t,c) ( uX(t,c).^2 + uY(t,c).^2 + uZ(t,c).^2 ).^0.5;
The formulation of the optimization problem includes some constraints and is formulated as
f = @(c) integral(@(t) fun(t,c),t0,tf);
x0 = ones(1,15);
A = [];
b = [];
Aeq = [... %Initial position and velocity constraints
1 t0 t0^2 t0^3 t0^4 zeros(1,5) zeros(1,5); ...
zeros(1,5) 1 t0 t0^2 t0^3 t0^4 zeros(1,5);...
zeros(1,5) zeros(1,5) 1 t0 t0^2 t0^3 t0^4;...
0 1 2*t0 3*t0^3 4*t0^3 zeros(1,5) zeros(1,5);...
zeros(1,5) 0 1 2*t0 3*t0^3 4*t0^3 zeros(1,5);...
zeros(1,5) zeros(1,5) 0 1 2*t0 3*t0^3 4*t0^3;...
...%Final position and velocity constraints
1 tf tf^2 tf^3 tf^4 zeros(1,5) zeros(1,5); ...
zeros(1,5) 1 tf tf^2 tf^3 tf^4 zeros(1,5);...
zeros(1,5) zeros(1,5) 1 tf tf^2 tf^3 tf^4;...
0 1 2*tf 3*tf^3 4*tf^3 zeros(1,5) zeros(1,5);...
zeros(1,5) 0 1 2*tf 3*tf^3 4*tf^3 zeros(1,5);...
zeros(1,5) zeros(1,5) 0 1 2*tf 3*tf^3 4*tf^3;...
];
beq = [initState; finalState];
lb = ones(1,15)*-inf;
ub = ones(1,15)*inf;
nonlc = [];
options = optimoptions(@fmincon,'Algorithm','interior-point',...
'MaxIterations',400,'StepTolerance',1.0e-12,...
'MaxFunctionEvaluations',3000,'Display','notify');
s = fmincon(@(a) f(a),x0,A,b,Aeq,beq,lb,ub,nonlc,options);
I'm running this iteratively over a period of 2000 (from 500-2500)
The result I get is far from optimal and so my question is.. is there something I did wrong in the formulation of this problem? (I'm particularly unsure about the computation of the integral.) Or could it just be something with the parameters of the optimization and should I try different settings?
Resulting plot should look something like:
but instead I'm given
thank you in advance for helping out

Best Answer

The first-order optimality measure is not that small at the end. I suspect that your problem is a bit sensitive. i see in your code that you can restart the optimization using the initial parameters from the optimization previously run. That is what I was going to tell you to try, but you already knew it.
Also, your problem has several linear equality constraints. Perhaps it would be worthwhile to try the 'sqp' algorithm instead of 'interior-point' especially after you run the optimization once to get a better starting point.
Some of your parameters might be quite large or small, and perhaps the problem could use some rescaling, though I am not sure where. I mean, Opt_Testing has a mu value of about 1e14, which is fairly large. I am not sure where this parameter enters into the calculation, but I'm sure that you understand it, and might know what could be rescaled. But I am not sure that this idea has any merit.
It is possible that trying a variety of initial points could provide a better solution. It also might be worth trying a smaller value of OptimalityTolerance, perhaps 1e-10, and for the 'interior-point' algorithm try setting the ScaleProblem option to true.
Well, this is not very satisfactory advice, I am afraid, as you already seem to know very well how to use the software. Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation