## 2 Models and Methods
### Optimization Approach and Solving Process  
Generally speaking, the trajectory optimization problem can be transformed into a nonlinear numerical optimal solution process by establishing a mathematical model. Some of the original conditions can be transformed into corresponding states and control constraints after transformation. The GPM is a direct global method, which has advantages in calculation efficiency and accuracy. Therefore, the GPM is use to solving this multi-phase optimization problem in this paper and the above optimization control problem can be disguised as a nonlinear programming problem. The basic idea of GPM is the polynomial interpolation of state and control variables in the whole time region [29] so that the continuous optimal control problem can be formally transformed. Hence, the problem is cleverly to become a traditional solution to solve process of nonlinear algebraic equations constrained by IPC, and the GPM solution steps are roughly as follows:  
Firstly, the time domain transformation for each phase is modified to transform the time period \(t^{n}\in\left[t_{0}^{n}-t_{7}^{n}\right]\) into time interval \(\tau^{n}\in[-1,1]\). Assuming that there are \(M\) numbers LG allocation points on each interval \(\tau^{n}\in[-1,1]\), and then those distribution points can be characterized as characteristic roots of Legendre polynomials in \(M\) numbers order [30]. As result, the state and control variables can be approximation by \(M+1\) order Legendre polynomials. Hence, the dynamic constraint equations can be converted to algebraic constraint equations by the above-approximation. Meanwhile, the boundary constraints also can be transcribed by \(\tau^{n}{}_{k}\), which is the \(k\) numbers of the LG points. At the same time, because the performance indicator function does not contain state variables, the total target optimization function still can be expressed by Equation (24).  
In summary, the original multi-phase continuous optimization problem for SPA can be transformed into nonlinear programming problem, which is defined by target optimization function in Equation (23) and dynamic constraints in above-mentioned. Besides, the optimization parameters can be obtained by a MATLAB software named Gauss pseudo-spectral Optimization Software (GPOPS) [31] with some reasonable optimality and feasibility tolerances.  
In this study, the angle of attack \(\alpha\), the roll angel \(\psi\) and the thrust \(T\) are chosen as three control variable to change the attitude and flight altitude of the SPA. The paper combines the GPOPS and function files of other models in Section 2 to solve the nonlinear programming problem for SPA in MATLAB. The optimization solving process is shown as follows.  
Step 1: Initialize the SPA parameters, geographical parameters and mission parameters.  
Step 2: Define the state and control variables and set up the limits on variables.  
Step 3: Provide boundary and initial values in each phase of the problem, and set up the event constraints which is linked in phases.  
Step 4: Provide an initial Mesh for each phase, the phase number is 5 and the LG allocation points number is 40 for each phase in this study.  
Step 5: Assemble all information into setup structure, which contains the aircraft kinematic model, aerodynamic model, solar irradiation and day-night cycle boundary conditions, etc., function files.  
Step 6: Load the target optimization function and the variable battery mass \(m_{bat}\) of SPA for satisfying the \(t_{5}-t_{0}=24\) h.m function files;  
Step 7: Solve the problem by using GPOPS in MATLAB;  
Step 8: Summarize the information of each node and phase to obtain the optimal flight trajectory for SPA base on energy reserving and mission altitude.