MatthewPeterKelly / OptimTraj

A trajectory optimization library for Matlab
MIT License
598 stars 207 forks source link

GPOPS-II Interpolation Function Handle returned by OptimTraj #20

Open stumarcus314 opened 7 years ago

stumarcus314 commented 7 years ago

In gpopsWrapper.m, OptimTraj provides an interpolation function handle for the GPOPS-II solution using pchip, as per the code below. Is pchip the most accurate way to interpolate the GPOPS-II solution?

soln.interp.state = @(t)( interp1(tSoln',xSoln',t','pchip',nan)' ); soln.interp.control = @(t)( interp1(tSoln',uSoln',t','pchip',nan)' );

The formula for the GPOPS-II state is given in equation (25) of the GPOPS-II paper:

Patterson, Michael A., and Anil V. Rao. "GPOPS-II: A MATLAB software for solving multiple-phase optimal control problems using hp-adaptive Gaussian quadrature collocation methods and sparse nonlinear programming." ACM Transactions on Mathematical Software (TOMS) 41.1 (2014): 1.

http://dl.acm.org/citation.cfm?id=2558904

MatthewPeterKelly commented 7 years ago

Excellent Question!

You're totally correct - the implementation for the OptimTraj interpolation of GPOPS-II solutions is not the correct way to perform this interpolation, but it does work quite well, because of how the tSoln, xSoln, and uSoln grids are constructed by GPOPS.

There would be two good ways to improve this interpolation: 1) If GPOPS-II updates their code to provide a function handle for interpolation, then we could just call that. 2) The correct interpolation formulas are already implemented in the ChebFun toolbox, which OptimTraj already has as a dependency (for the Chebyshev method). The tricky part is extracting the correct segment bounds when performing the interpolation.

Why was the code written this way? Like most short-comings in this toolbox, because I just didn't have enough time. I originally implemented the wrapper for GPOPS-II to verify that my solutions were correct. At the time, I was just using the interp() method for making nice plots. It was never worth the day or two of programming time that it would take to make the interpolation use the correct formulas.

How large are the errors? Let's say that GPOPS has a single 5th-order segment. Here, I would interpolating it using six 3rd-order segments. This should be a pretty good approximation, provided that the 5th-order segment is well behaved, which it will be for the vast majority of segments. If anyone has time to work out the specific math, let me know! This would be a great numerical methods extra credit problem.

areusiriuses commented 5 years ago

May i ask a question that how to get pneumatic parameter using interpolation? I have alredy got the oringinal data ponits of pneumatic parameter but i want to get the pneumatic parameter with specific Mach number and Angle of attack...thankyou

MatthewPeterKelly commented 5 years ago

I'm going to need a bit more context to answer your question... but here is a guess:

1) Pneumatic parameter is known ahead of time, and is stored as tabulated data as a function of mach number and angle of attack. In this case you will need to generate an interpolation function. I suggest that you use bi-cubic interpolation, which matlab has built-in tools for. Linear interpolation is easier, but has a non-smooth gradient which can mess up the optimization.

2) Pneumatic parameter is one of your states (or controls) in the optimization problem. In this case, you can interpolate it using the function handle (or PP-form struct) returned by OptimTraj for any method.

On Tue, Apr 30, 2019 at 12:45 AM areusiriuses notifications@github.com wrote:

May i ask a question that how to get pneumatic parameter using interpolation? I have alredy got the oringinal data ponits of pneumatic parameter but i want to get the pneumatic parameter with specific Mach number and Angle of attack...thankyou

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/MatthewPeterKelly/OptimTraj/issues/20#issuecomment-487819876, or mute the thread https://github.com/notifications/unsubscribe-auth/AB6CWOIUJE5S4MCRKYGZONDPS7FGPANCNFSM4CPEWK5A .

areusiriuses commented 5 years ago

THANK YOU~I have solved this problem