File Exchange

## Gravity-assist Trajectory Design and Analysis

version 2.0.0.0 (670 KB) by
A MATLAB Script for Interplanetary Gravity-Assist Trajectory Design and Optimization

Updated 20 Sep 2019

PDF document and a MATLAB script called flyby_matlab that can be used to design and optimize interplanetary trajectories that include a single gravity assist maneuver. The user specifies the launch, flyby and destination planets, and the desired flyby altitude. The algorithm also requires initial guesses for the launch, flyby and arrival calendar dates. This script searches for a patched-conic gravity-assist trajectory that satisfies the flyby mission constraints (V-infinity matching and user-defined flyby altitude) and minimizes the launch, arrival or total impulsive delta-v for the mission. The type of delta-v optimization is specified by the user.

### Cite As

David Eagle (2020). Gravity-assist Trajectory Design and Analysis (https://www.mathworks.com/matlabcentral/fileexchange/39462-gravity-assist-trajectory-design-and-analysis), MATLAB Central File Exchange. Retrieved .

Alicia Harris

Error message is still displayed after following the steps. Is it a licence issue? I was only able to obtain the Student and not the commercial license.

David Eagle

Recommended setup (1) create a sub-directory named flyby_matlab (for example) (2) copy all files from flyby_matlab.zip to this directory (3) copy all SNOPT files and the DE421 ephemeris file to this sub-directory (4) log in to this sub-directory from within MATLAB (5) run the script in the flyby_matlab sub-directory

Brian Claytor

Hello, I followed the SNOPT steps by Mick Smith, and the following error occurred:
"Error using snoptmex
Error in snopt (line 294)
xstate,Fstate,itn,mjritn] = snoptmex(solveopt, ...
Error in t1diet (line 12)
[x,F,INFO,xmul,Fmul,xstate,Fstate,output]= snopt( x, xlow,
xupp, xmul, xstate, ...
Error in runNPexamples (line 10)
[x,xmul,F,Fmul,info] = t1diet;"
Any idea on how to fix this issue?

Mick Smith

For everyone below that was having trouble getting this to work:

For SNOPT:
1. Go here to request a license for SNOPT (snopt7.lic) and to get the snoptmex file: https://ccom.ucsd.edu/~optimizers/downloads/
3. Move the snopt7.lic and snoptmex file into the snopt-matlab-2.5.0 file you downloaded in part 2
4. On Matlab, go to Home - > Environment - > Set Path
5. Click 'Add with subfolders' and then click the snopt-matlab-2.5.0
6. In the matlab terminal type setenv('SNOPT_LICENSE','C:\Users\User\Documents\MATLAB\snopt-matlab-2.5.0\snopt7.lic')
hit enter and then type runNPexamples to test the NLP solver. If no errors occur then it's working.

For JPL ephemeris:
1. Go to this website: https://cdeaglejr.wordpress.com
2. Find 'Ephemeris Binary Files' and click on the dropbox link

Getting the de421.bin file will solve the "userfun should return 1 or 2 arguments" error.

ahmed morsi

can you give me instructions for using SNOP with Gravity-assist Trajectory Design and Analysis. thank you.

Subham Kumar Gupta

Okay it's great to be honest. I have a small problem though and it's kind of a pain. I am unable to run the snopt function. When I try to run it I get the following error:
Error using snopt (line 189)
userfun should return 1 or 2 arguments

Zhi Ming Lin

Jin Heng Choi

I think there is miss-typing in " fbyfunc"
In this code, the equation to obtain the turn angle is typed as below
phi1 = 0.5 * pi + 0.5 * asin(v1crossv2m / (vinfm_in * vinfm_out));

but I think it should be fixed like this
phi1 = 0.5 * pi - 0.5 * asin(v1crossv2m / (vinfm_in * vinfm_out));

can you check for me ?

Vicente Alvero

When compiling the program I get the following error, can you help me please?

error: userfun should return 1 or 2 arguments
error: called from
snopt at line 188 column 5
flyby_matlab at line 356 column 23
>>

Guillermo Centelles

Undefined function or variable 'snopt'.

Error in flyby_matlab (line 356)
[x, f, inform, xmul, fmul] = snopt(xg, xlwr, xupr,
xmul, xstate, ...

Where is the snopt function defined?