Make this optimization work
Risposte (1)
Hi @Ionel,
Your `FiniteDifferenceStepSize = 1e-6` is way too small for an ODE-based optimization. fmincon is testing gains like 0.000001 vs 0, which produces literally zero detectable difference in your 5-second simulation. It sees "gradient = 0" and quits immediately (that's why you got 19 function calls and stopped).
Quick fix:
'FiniteDifferenceStepSize', 0.1 % instead of 1e-6
**Better fix - use pattern search instead:
options = optimoptions('patternsearch', 'Display', 'iter', 'MaxIterations', 1000);
[opt_gains, ~] = patternsearch(@cost_function, x0, [], [], [], [], lb, ub, options);
Pattern search doesn't rely on gradients so it's much more robust for simulation-based problems like yours.
Also don't start at zero - try `x0 = [1,1,1,1,1,1,1,1,1]` instead.
The MathWorks docs specifically warn about this: " Simulations are often insensitive to small changes in parameters. If you use too small a perturbation, the simulation returns a spurious derivative of 0."
Questions to Consider
1.Does your simulation complete successfully with gains = [1,1,1,1,1,1,1,1,1]?
2. What cost value do you get with manual gain tuning?
3. Are you sure the desired states are achievable? (vx=0, vy=5 m/s, pitch=90 degrees, forward motion from x=0 to somewhere?)
I hope this helps! Let me know if you'd like me to clarify anything or if you encounter new issues after implementing these changes.
P.S. Your 6DOF model looks quite sophisticated with proper Mars atmosphere modeling (temperature, pressure, density), variable mass/inertia, aerodynamic drag with Reynolds number calculation, and RCS thruster control. Once the optimization is working, you should get good results!
Categorie
Scopri di più su Quadratic Programming and Cone Programming in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!