lunar lander truss project - university of michigan

35
Lunar Lander Truss Project AERO 423 - Aerospace Computational Methods University of Michigan - Ann Arbor February 14, 2020 Prepared by: Drake Rundell Image Source: https://www.needpix.com/photo/90155/apollo-moon-landing-nasa-usa-space-travel

Upload: others

Post on 25-Nov-2021

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lunar Lander Truss Project - University of Michigan

Lunar Lander Truss Project

AERO 423 - Aerospace Computational Methods

University of Michigan - Ann Arbor

February 14, 2020

Prepared by:Drake Rundell

Image Source: https://www.needpix.com/photo/90155/apollo-moon-landing-nasa-usa-space-travel

Page 2: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

Table of Contents

I List of Figures ii

II List of Equations ii

III Problem Description iii

IV Parameters v

V Numerical Approach v

1 Equations of Motion for a Free Node and for the Lunar Lander 11.1 Equations of Motion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 MATLAB Implementation of EOMs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.3 Function with Initial Equilibrium Condition . . . . . . . . . . . . . . . . . . . . . . . . . . 2

2 Approximate Jacobian Matrix for Time-Step Restriction 32.1 Constructed Jacobian Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32.2 Eigenvalues Plot of the Jacobian Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.3 Time-Step Restriction for Numerical Schemes . . . . . . . . . . . . . . . . . . . . . . . . . 4

2.3.1 Forward Euler Numerical Scheme Stability . . . . . . . . . . . . . . . . . . . . . . 52.3.2 Adams Bashforth Numerical Scheme Stability . . . . . . . . . . . . . . . . . . . . 62.3.3 Runge-Kutta Numerical Scheme Stability . . . . . . . . . . . . . . . . . . . . . . . 7

3 Implementation of Forward Euler (FE), Adams Bashforth (AB2), and Runge Kutta (RK4) 83.1 Forward Euler Numerical Scheme Implementation . . . . . . . . . . . . . . . . . . . . . . 83.2 Adams Bashforth Numerical Scheme Implementation . . . . . . . . . . . . . . . . . . . . . 93.3 Runge-Kutta Numerical Scheme Implementation . . . . . . . . . . . . . . . . . . . . . . . 103.4 Evidence of Instability at Doubled Time-Steps . . . . . . . . . . . . . . . . . . . . . . . . . 12

4 Plot Height of Lander as a Function of Time 13

5 Runge-Kutta Simulation of Lunar Lander Truss 14

6 Time-Step Convergence Study to Determine Theoretical Convergence Rate 16

7 Conclusion 17

A Appendix A-1A.1 List of Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-1A.2 MATLAB Script Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-1A.3 MATLAB Function Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-7

i

Page 3: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

I List of Figures

1 Lunar Lander Setup Scheme . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iii2 Force in One Link . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iv3 Jacobian Matrix Eigenvalue Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 Forward Euler Eigenvalue Stability Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Adam Bashforth Eigenvalue Stability Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 Runge-Kutta Eigenvalue Stability Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 Initial Lunar Lander Truss Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88 Lunar Lander Truss Layout with Forward Euler . . . . . . . . . . . . . . . . . . . . . . . . 99 Lunar Lander Truss Layout with Adams Bashforth . . . . . . . . . . . . . . . . . . . . . . 1010 Lunar Lander Truss Layout with Runge-Kutta . . . . . . . . . . . . . . . . . . . . . . . . . 1111 Instability With Double Time-Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1212 Lunar Lander Height as Function of Time . . . . . . . . . . . . . . . . . . . . . . . . . . . 1313 Time Captures of the Deformation in the Lunar Lander Truss . . . . . . . . . . . . . . . . . 1414 Time-Step Convergence Study Plot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

II List of Equations

1 Link Force Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iii2 Format Definition of Node Iteractions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iv3 Change in Link Length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iv4 Change in Link Length in Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iv5 Pointing Vector of Link . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iv6 Force from Node i to Node j . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iv7 Force from Node j to Node i . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iv8 Equation of Motion Form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v9 Equations of Motion for Free Nodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110 Equations of Motion of Lunar Lander . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 Node State Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 State Vector Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213 Jacobian Matrix of Dynamic Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314 Analytical First Derivative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315 Eigenvalue Stability Equation of Forward Euler . . . . . . . . . . . . . . . . . . . . . . . . 516 Eigenvalue Stability Equation of Adams Bashforth . . . . . . . . . . . . . . . . . . . . . . 617 Amplification Factor Equation of Runge Kutta . . . . . . . . . . . . . . . . . . . . . . . . . 718 Error in Height Calculation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

ii

Page 4: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

III Problem Description

The project will simulate the landing of robotic lunar rover. The landing dynamics are determined by thelander legs, which are flexible trusses that absorb the kinetic energy of a landing. The setup is illustrated inthe figure below.

Figure 1: Lunar Lander problem setup that features a lander with four legs; in the figure only two are shown with theother two out of the plane of the page and not shown.

The lander has four legs, but only one will be simulated, shown on the right in the above figure. The otherlegs are calculated from the right leg since they are all symmetric. In addition, in-plane deformation willbe assumed so that the problem remains two-dimensional. Each leg consists of a truss of nodes and links,as indicated above. Nodes 8 and 9 are bolted to the lander, and cannot move relative to each other; instead,these move vertically with the lander. In addition, upon landing, nodes 6 and 7 dig into the soil and cannotmove.

On the other hand, nodes 1-5 can move arbitrarily, and their motion is dictated by the forces acting throughthe links to which they are attached. Finally, the motion of the lander is determined by the forces acting onit, which are its weight and the forces of the legs acting through the attachment points.

Link Force Calculation

The nodes move because of the forces exerted on them by the links. It is assumed that these links have nomass (they are very light relative to the nodes) and that the tensile force in a link depends on how much thelink is stretched, δ l, and how fast it is being stretched, δ l:

Flink = kδ l + γδ l (1)

iii

Page 5: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

To calculate the resulting force contributions at the two adjacent nodes - called i and j a few definitions mustbe made:

Figure 2: Force in one link.

xi = [xi,yi] = position of node i

x j = [x j,y j] = position of node j

vi = [ui,vi] = velocity of node i

v j = [u j,v j] = velocity of node j

l0 = initial length of this link

(2)

The quantities appearing in Equation 1 can then be calculated as:

δ l = |x j − xi|− l0 (3)

δ l = (x j − xi) · ei j (4)

where |·| refers to the magnitude of a vector and

ei j =x j − xi

|x j − xi|(5)

The force on nodes i and j due to this link are, respectively,

Fi j = Flinkei j (6)

Fji =−Flinkei j (7)

As shown above, a positive Flink corresponds to a tension force that pulls the nodes closer together. δ l is apositive when the link is stretched longer than its initial equilibrium length, and δ l is positive when the linkis actively being stretched. So kδ l is then a restorative force, while γδ l is a damping term. At every node,the forces from the links sum together to exert a net force on the node. The node’s acceleration is given bythis total force divided by the node mass.

iv

Page 6: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

Dynamics

Each free node of the truss in the lunar lander leg can move in the x and y direction. The acceleration ofa free node is caused by the forces acting on it: its weight and the forces from the adjacent links. Thelunar lander moves only vertically, by symmetry of the legs. The lander’s (vertical) acceleration is causedby its own weight and the forces of the legs acting through nodes 8 and 9. At t = 0, the legs are in theirequilibrium configuration, shown in Figure 1, with nodes 6 and 7 having just hit the ground, and with therest of the nodes, and the lander, moving downward at speed V .

IV Parameters

The parameters relevant to the problem are listed below. Note, the lunar lander mass includes the masses ofthe affixed nodes, 8 and 9, from each leg.

T = 0.5 [s] Time Horizonmmode = 0.1 [kg] Node MassM = 100 [kg] Lander Massd = 0.2 [m] Initial Truss Width/Heightk = 105 [N/m] Link Stiffnessγ = 200 [Ns/m] Link Dampingg = 1.625 [m/s2] Acceleration Due to GravityV = 6 [m/s] Initial Impact (descent) Speed

V Numerical Approach

To simulate the dynamics of the truss, use a state vector of 22 entries: the (x,y) positions and velocities ofthe 5 free nodes, and the height and vertical velocity of the lunar lander. The equations of motion will be ofthe form:

u = f(u) (8)

where f contains the physics (force-balance) calculations.

Three numerical integration techniques will be used to solve this system of ODEs: Forward Euler, second-order Adams Bashforth, and fourth-order Runge Kutta. When discretizing time, a constant time step ∆t =T/Nt will be used, where Nt is the number of time steps.

v

Page 7: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

1 Equations of Motion for a Free Node and for the Lunar Lander

Using the equations of motion for a free node and for the lunar lander, a function can be programmed thattakes input of the state, u, and any other required parameters, and computes the vector f. Using the statecorresponding to the initial equilibrium configuration, V = 0, and g = 0, the verification can be made thatthe function returns f identically equal to zero.

1.1 Equations of Motion

EOM for Free Nodes (1-5):�

xi

yi

�=

1mnode

�elements

∑i=1

kδ l + γδ l ei j

�−�0g

�(9)

EOM for Lunar Lander (Nodes 8-9):�xi

yi

�=

8M

�elements

∑i=1

kδ l + γδ l ei j

�−�0g

�(10)

1.2 MATLAB Implementation of EOMs

In order to create a function which outputs the vector f, a function to calculate the summation of the forceson each node must be created. This function will take in the given node state, a matrix of the position inx and y, and the velocity in u and v, along with the specific node of interest and output the summation offorces. The node state is written as such:

u =

x1 y1 u1 v1x2 y2 u2 v2x3 y3 u3 v3x4 y4 u4 v4x5 y5 u5 v5x6 y6 u6 v6x7 y7 u7 v7x8 y8 u8 v8x9 y9 u9 v9

(11)

The organization of the node state will allow for the plotting of the node state at given time steps in futurenumerical schemes. The summation of forces using this node layout is done by creating a for loop whichloops to the maximum size of the inputted nodes matrix. Within the loop, each node is read against a list ofcorresponding nodes to determine the initial distance of the links. The links are either initially 0.2 or 0.2828meters. Once the distance is found, the force of the node of interest and the surrounding nodes is summedtogether and the function outputs the total force.

The f function can now be written to take in the node state u and output f. The function turns a state vectorof positions and velocities into a vector of velocities and accelerations using the above equations of motion,while also accounting for the boundary conditions on nodes 6 and 7. Nodes 6 and 7 are not able to movefrom their bounded state due to their placement into the lunar surface. Therefore, the function sets the foutput for these nodes to all zeroes. The free node states are calculated using the respective equation of

1

Page 8: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

motion. The lunar lander state is also calculated using its equation of motion with respect to the connectednodes of 8 and 9. However, the boundary condition that nodes 8 and 9 must remain 0.2 meters apart in they direction is enforced through the neglecting of x plane velocities and accelerations.

The output of the f function turns the input of a matrix of node positions and velocities into a 36×1 columnvector with the following form for all nine nodes:

f(u) =

u1v1u1v1...

u9v9u9v9

(12)

The function f(nodes) in the MATLAB code in the appendix reflects the imposed boundary conditionsdiscussed, as well as the function that calculates the summed force at each node. The force summationfunction node_force(nodes,node) is also shown in the appendix code block.

1.3 Function with Initial Equilibrium Condition

The state corresponding to the initial equilibrium condition where V = 0, and g = 0, has been verified tooutput a vector of all zeros. This is expected output since there would be no forces acting on any of thenodes as the lander and truss system would simply be “sitting” in free space. In this equilibrium case, theoutput is a 36×1 column vector of all zeros.

f(u) =[0 0 0 0 . . . 0 0 0 0

]′Note: this column vector is shown as transposed to allow for better readability.

2

Page 9: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

2 Approximate Jacobian Matrix for Time-Step Restriction

By perturbing individual components of the state vector u from the initial configuration and repeatedlycalling the f function, an approximate Jacobian Matrix, δ f

δu , can be constructed. The eigenvalues of this22×22 matrix can be found in the complex number plane and used to graphically determine the time-steprestriction for the time stepping methods used.

2.1 Constructed Jacobian Matrix

The δ fδu matrix can be constructed by perturbing individual components of the state vector u by a small

amount of 1× 10−6. This perturbation will be referred to as h. The matrix will be constructed with thefollowing form:

δ fδu

=

δ f1δx1

δ f1δx2

δ f1δx3

. . . δ f1δxn

δ f2δx1

δ f2δx2

δ f2δx3

. . . δ f2δxn

......

.... . .

...δ fnδx1

δ fnδx2

δ fnδx3

. . . δ fnδxn

(13)

To find each individual derivative in the matrix Newton’s difference quotient will be used. Using a limit asthe h value approaches zero, the limit of the derivative of the function is defined as:

f ′(a) = limh→0

f (a+h)− f (a)h

(14)

In this case, each part of the δ fδu matrix will need to filled in using this derivative function. In MATLAB, a

function called dfdu_matrix(nodes) was created to output the 22×22 matrix using an input of the initialnode state.

3

Page 10: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

2.2 Eigenvalues Plot of the Jacobian Matrix

The eigenvalues of the now populated 22×22 matrix created using perturbed components can be calculatedusing the built-in MATLAB function eig(matrix). The eigenvalue output of this function can then beplotted on imaginary versus real axes. Shown below is the plot of the eigenvalues for the δ f

δu matrix.

Figure 3: Plot of the derivative matrix showing the real and imaginary parts of the eigenvalues used to determine thescaling of the maximum time step.

As seen in the above figure, the smallest real root on the plot is −8726. This value will be important inconjunction with the roots of each eigenvalue stability equation for the numerical methods Forward Euler,Adams Bashforth, and Fourth Order Runge-Kutta. The value will be used in the determination of scalingfor the eigenvalues to place them into a stable regime to calculate the maximum allowable time step for theschemes.

2.3 Time-Step Restriction for Numerical Schemes

To find the maximum allowable time step for the numerical schemes in the case of the lunar lander dynamics,the eigenvalue stability plot must first be generated for each scheme. The plot will allow for the scaling ofthe δ f

δu eigenvalues inside the stable regime.

4

Page 11: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

2.3.1 Forward Euler Numerical Scheme Stability

The eigenvalue stability of Forward Euler is given by the following equation:

λ∆t = eiθ −1 (15)

The equation can be plotted by specifying a θ which ranges from 0 to 2π . Much like the above figure,the real and imaginary parts of the equation are plotted to reveal a stability region. By observing that thesmallest real root available on the Forward Euler contour as −2, a scaling factor can be created in order tofit the eigenvalues of the δ f

δu matrix inside the stable regime.

scaleFE =−8726−2

Applying this scaling factor to all the eigenvalues of δ fδu , the plot below can be created to show all values are

now in the stable regime.

Figure 4: Plot of the eigenvalues of Forward Euler with the applied scaling factor to fit the eigenvalues of the δ fδu

matrix inside the stability region.

The inverse of the scaling factor also reveals the maximum allowable time step for the Forward Euler nu-merical scheme with the given dynamics.

∆tFE = 2.2914×10−4 s

The restriction on the time step is it must be less than this value or else the time-stepping method will beunstable and result in incorrect computations.

5

Page 12: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

2.3.2 Adams Bashforth Numerical Scheme Stability

The eigenvalue stability of Adams Bashforth is given by the following equation where g = eiθ :

λ∆t = (g−1)2g

3g−1(16)

The equation can be plotted by specifying a θ which ranges from 0 to 2π . By observing that the smallestreal root available on the Adams Bashforth contour as −0.9997, a scaling factor can be created in order tofit the eigenvalues of the δ f

δu matrix inside the stable regime.

scaleAB2 =−8726−0.9997

Applying this scaling factor to all the eigenvalues of δ fδu , the plot below can be created to show all values are

now in the stable regime.

Figure 5: Plot of the eigenvalues of Adams Bashforth with the applied scaling factor to fit the eigenvalues of the δ fδu

matrix inside the stability region.

The inverse of the scaling factor also reveals the maximum allowable time step for the Adams Bashforthnumerical scheme with the given dynamics.

∆tAB2 = 1.1456×10−4 s

The restriction on the time step is it must be less than this value or else the time-stepping method will beunstable and result in incorrect computations.

6

Page 13: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

2.3.3 Runge-Kutta Numerical Scheme Stability

The eigenvalue stability of 4th Order Runge-Kutta is given by the following equation where g = eiθ :

g = 1+λ∆t +12(λ∆t)+

16(λ∆t)3 +

124

(λ∆t)4 (17)

The equation must be numerically solved for λ∆t at a θ which ranges from 0 to 2π . Once the system offour equation is solved, the stability plot can be made by plotting the real and imaginary parts of λ∆t. Byobserving that the smallest real root available on the Runge-Kutta contour as −2.7853, a scaling factor canbe created in order to fit the eigenvalues of the δ f

δu matrix inside the stable regime.

scaleRK4 =−8726−2.7853

Applying this scaling factor to all the eigenvalues of δ fδu , the plot below can be created to show all values are

now in the stable regime.

Figure 6: Plot of the eigenvalues of Runge-Kutta with the applied scaling factor to fit the eigenvalues of the δ fδu matrix

inside the stability region.

The inverse of the scaling factor also reveals the maximum allowable time step for the Runge-Kutta numer-ical scheme with the given dynamics.

∆tRK4 = 3.1919×10−4 s

The restriction on the time step is it must be less than this value or else the time-stepping method will beunstable and result in incorrect computations.

7

Page 14: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

3 Implementation of Forward Euler (FE), Adams Bashforth (AB2), andRunge Kutta (RK4)

The implementation of Forward Euler, second-order Adams-Bashforth, and fourth-order Runge-Kutta timeintegration is detailed in this section. The verification of the maximum time steps calculated in the previoussection will take place to ensure stability of the methods. For comparison purposes, a plot of the initialconfiguration of the lunar lander truss is shown below. This will be used to show that the implementation ofthese schemes results in a convergent and stable solution.

Figure 7: Plot of the lunar lander truss at T = 0 before any numerical scheme is applied in order to show a comparisonbetween dynamic and non-dynamic movement of the truss.

3.1 Forward Euler Numerical Scheme Implementation

Forward Euler numerical method was implemented based off the following iteration equation:

un+1 = un +∆tf(un)

Using this iteration equation a function called FE(nodes,t) was created in MATLAB to repeatedly call thefunction f. The input to the function is the state of the nodes in matrix form as described in the past details,as well as a vector of time that is based off of the time period of 0 to 0.5 seconds using the maximum timestep decreased by 3% to ensure stability is maintained. Within the function calculates the ∆t value by thedifference of the first two time steps in the time vector.

8

Page 15: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

The function then preallocates the output array using the size of the input node matrix and time step. Next,the node matrix is organized into a column state vector before that vector is used in the scheme. Since thef function takes input as the node matrix, a temporary matrix is created from the column state vector to beused as input. A for loop repeats these steps continually until the N − 1 index is reached, where N is themaximum number of entries in the time vector.

Figure 8: Plot of the lunar lander truss at T = 0.5 after all iterations of the Forward Euler scheme have taken placeshowing that stability is maintained at the tweaked maximum time-step values.

The plot of the lunar lander truss shows the iteration successfully converges and results in an expected resultfor a truss experiencing a load. Therefore, verification of the Forward Euler implementation is completedand can be relied on for the future simulations and results.

3.2 Adams Bashforth Numerical Scheme Implementation

Adams Bashforth numerical method was implemented based off the following iteration equations:

un+1 −un = ∆t�

32

f(un, tn)− 12

f(un−1, tn−1)

Using this iteration equation a function called AB2(nodes,t) was created in MATLAB to repeatedly callthe function f. The input to the function is the state of the nodes in matrix form as described in the pastdetails, as well as a vector of time that is based off of the time period of 0 to 0.5 seconds using the maximumtime step decreased by 3% to ensure stability is maintained. Within the function calculates the ∆t value bythe difference of the first two time steps in the time vector.

The function then preallocates the output array using the size of the input node matrix and time step. Next,the node matrix is organized into a column state vector before that vector is used in the scheme. SinceAdams Bashforth relies on two steps in time, an additional step in time was generated using one iteration ofForward Euler. This allows for the AB2 scheme to begin as there are now two known states. The f functiontakes input as the node matrix, therefore a temporary matrix is created from the column state vector to be

9

Page 16: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

used as input. A for loop repeats these steps continually until the N − 1 index is reached, where N is themaximum number of entries in the time vector.

Figure 9: Plot of the lunar lander truss at T = 0.5 after all iterations of the Adams Bashforth scheme have taken placeshowing that stability is maintained at the tweaked maximum time-step values.

The plot of the lunar lander truss shows the iteration successfully converges and results in an expected resultfor a truss experiencing a load. Therefore, verification of the Adams Bashforth implementation is completedand can be relied on for the future simulations and results.

3.3 Runge-Kutta Numerical Scheme Implementation

Fourth Order Runge-Kutta Euler method can be implemented using the following update equation:

f0 = f(un, tn)

f1 = f(un +12

∆tf0, tn +∆t2)

f2 = f(un +12

∆tf1, tn +∆t2)

f3 = f(un +∆tf2, tn +∆t)

un+1 = un +∆t6(f0 +2f1 +2f2,+f3)

Using this iteration equation a function called RK4(nodes,t) was created in MATLAB to repeatedly callthe function f. The input to the function is the state of the nodes in matrix form as described in the pastdetails, as well as a vector of time that is based off of the time period of 0 to 0.5 seconds using the maximumtime step decreased by 3% to ensure stability is maintained. Within the function calculates the ∆t value bythe difference of the first two time steps in the time vector.

The function then preallocates the output array using the size of the input node matrix and time step. Next,the node matrix is organized into a column state vector before that vector is used in the scheme. Since the

10

Page 17: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

f function takes input as the node matrix, a temporary matrix is created from the column state vector tobe used as input. The fourth order Runge-Kutta method relies on multiple steps within one time iteration,which deemed it necessary to have each of these steps continually calculated. A for loop repeats these stepscontinually until the N −1 index is reached, where N is the maximum number of entries in the time vector.

Figure 10: Plot of the lunar lander truss at T = 0.5 after all iterations of the Runge-Kutta scheme have taken placeshowing that stability is maintained at the tweaked maximum time-step values.

The plot of the lunar lander truss shows the iteration successfully converges and results in an expected resultfor a truss experiencing a load. Therefore, verification of the Runge-Kutta implementation is completed andcan be relied on for the future simulations and results.

11

Page 18: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

3.4 Evidence of Instability at Doubled Time-Steps

Using the height of the lunar lander (node 8) as a function of time, the instability of the numerical schemewhen using a time-step double in value of the maximum allowable time-steps respective to the schemes canbe seen. This doubled time-step value puts the eigenvalues of the Jacobian matrix out of the stable regimethat was previously defined. Therefore, none of the iterative methods converge to a proper solution and theresults are astronomically large numbers.

Figure 11: Plot of the instability associated with a doubled maximum time-step.

The above plot shows why it is important to determine the maximum allowable time-step and ensure thevalue used is some percent less than that for the numerical schemes to remain stable. The tweaked valueused of a 3% decrease on this maximum time step will continue to be used to keep stability in the schemes.

12

Page 19: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

4 Plot Height of Lander as a Function of Time

Using Forward Euler, Adams Bashforth, and fourth order Runge-Kutta, simulations can be performed up toT = 0.5 with the largest possible time step for each method tweaked by a 3% decrease in order to plot theheight of the lander. This plot will be height as function of time. The previously discussed functions andimplementations are used to find the height of node 8, which corresponds to the actual lander height. Aftersimulations are ran, the y component of node 8 is pulled out of the state vector for every time iteration. Thisis done for each numerical scheme to create the plot shown below.

Figure 12: Plot of the oscillatory lunar lander height from 0 to 0.5 seconds using all three numerical schemes to seethe differences imposed by each.

The differences in the methods can be seen in the plot. The Runge-Kutta and Adams Bashforth implemen-tation are extremely similar and typically produce the same height value at each time interval; however, theForward Euler differs in height, but still remains within expected error bounds for a first order numericalscheme. In the case a necessary method must be picked to use in future scenarios, Runge-Kutta wouldbe best due to high convergence rate and accuracy as it is a fourth order approximation of the numericalsolution.

13

Page 20: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

5 Runge-Kutta Simulation of Lunar Lander Truss

The fourth order Runge-Kutta simulation can be ran at the largest possible time step with the aforemen-tioned 3% tweak to ensure stability remains as the truss deforms. The nodes and links are plotted att = 0.05,0.1,0.15,0.2,0.25,0.3,0.35,0.4,0.45 seconds. These plots are seen below with the labeled timeinstances in the free space of each plot.

Figure 13: The nodes and links of the Lunar Lander truss are plotted at t = 0.05,0.1,0.15,0.2,0.25,0.3,0.35,0.4,0.45seconds showing the deformation undergone in the system due to the dynamics in the x and y plane.

14

Page 21: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

The plots were generated using a function named plotNodes which takes in the node state matrix andthe current time and outputs a figure of the plotted nodes and links and saves the image file for easy ac-cess and publishing. The state space column was converted to the node state matrix using the functionnodeSpace2nodes(nodeSpace).

The truss deforms as expected for a system taking a large load with a high downward velocity. The os-cillatory nature of the truss is shown through the bouncing effect of the lunar lander and respective nodes.Looking at node 8 shows the height of the lander itself is changing as a function of time which correspondsto what was observed in the height as a function of time plot in the above section. This nature is commonamong dynamically damped systems and coincides with what is to be expected in a low gravity atmosphere,given link damping coefficient, and link stiffness.

Not included in this report due to the technicality of the file format was the creation of a .gif file encapsulatingthe motion of truss from 0.01 to 0.5 seconds with a frame taken every 0.05 seconds. The animated imageshowed the oscillatory motion of the truss and how the damping of the system begins as the oscillations slowdown and decrease in magnitude. The .gif is a great way of observing the nature of the lunar lander truss asit allows for another visual aspect to verify the simulations were ran satisfactory and produced valid results.

15

Page 22: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

6 Time-Step Convergence Study to Determine Theoretical Convergence Rate

Using the lander position at T = 0.5 as the output, a time-step convergence study can be completed todemonstrate that the theoretical convergence rate was achieved for each method. The exact solution wasdetermined by using the Runge-Kutta function with 100,000 time steps in order to provide an extremelyaccurate solution. The other refined time steps for Forward Euler, Adams Bashfroth, and Runge-Kutta werethen simulated and the output of the height of the lander at the final time was extracted and the error wascalculated with the simple equation:

eh = |hexact −hsimulated | (18)

The error was then plotted on a loglog scale to compare the time-steps with the calculated error. This plotis shown below and features a legend with the slope of each error line. The slope is equivalent to theapproximate convergence rate of the utilized method.

Figure 14: Plot of the convergence of the numerical methods used to determine if the theoretical convergence ratewas achieved.

As shown by the figure, the convergence rate achieved for Forward Euler with the given dynamics was1.0145, this coincides with the theoretical expected rate of a first order iterative scheme denoted by O(∆t).For the Adams Bashforth method the slope was observed as 1.9984, which is approximately equal to the sec-ond order theoretical solution of a second order scheme, O(∆t2). The theoretical fourth order Runge-Kuttamethod is also shown as the numerical scheme reaches a slope of 4.3074 for the implemented dynamics,showcasing a convergence rate of O(∆t4). Therefore, all schemes have been demonstrated to output at thetheoretical convergence rate

16

Page 23: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

7 Conclusion

The following document details the process used to construct the simulation of a lunar lander using differ-ential equations based on the physics of damped oscillations of stiff links connected to nodes in a truss. Thestability regimes of the equations of motion were found for three numerical schemes, Forward Euler, AdamsBashforth, and Runge-Kutta. The maximum time-step value was then used to produce a simulated heightplot as function of time to show the oscillatory nature of the dynamic equations of motion. The schemeswere compared against themselves to ensure quality results were obtained. The fourth order Runge-Kuttascheme was used to generate plots of the truss at given time intervals to ensure the deformations coincidewith physical intuition. The convergence of each implemented scheme was verified to ensure an approxi-mate theoretical convergence order was achieved. The simulation of the lunar lander allowed for a real lifeapplication of a physical system using numerical methods on partial differential equations.

17

Page 24: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

A Appendix

The MATLAB code ran to generate the plots and numerical results in this document is attached below.Some function calls have been commented out in order to save time when running the code as locally storedmatrices of values resulted in much better performance run time.

A.1 List of Algorithms

1 MATLAB Script used to call implemented functions. . . . . . . . . . . . . . . . . . . . . . A-12 Function responsible for converting column space vector into node matrix . . . . . . . . . . A-73 Function responsible for outputing Jacobian matrix . . . . . . . . . . . . . . . . . . . . . . A-74 Function responsible for Runge-Kutta Implementation . . . . . . . . . . . . . . . . . . . . A-85 Function responsible for Adams Bashforth Implementation . . . . . . . . . . . . . . . . . . A-96 Function responsible for Forward Euler Implementation . . . . . . . . . . . . . . . . . . . . A-97 Function responsible for output of accelerlation and velocity state space . . . . . . . . . . . A-108 Function responsible for summation of forces on a node . . . . . . . . . . . . . . . . . . . . A-109 Function responsible for plotting truss layout in 2D . . . . . . . . . . . . . . . . . . . . . . A-12

A.2 MATLAB Script Implementation

1 %Drake R u n d e l l2 %AE 423 − P r o j e c t 13 %Due : 2 / 1 4 / 2 0 2 04

5 c l e a r ; c l c ; c l o s e a l l ;6 s e t ( g r o o t , ’ D e f a u l t T e x t I n t e r p r e t e r ’ , ’LaTeX ’ ) ;7 s e t ( g r o o t , ’ D e f a u l t A x e s T i c k L a b e l I n t e r p r e t e r ’ , ’LaTeX ’ ) ;8 s e t ( g r o o t , ’ D e f a u l t L e g e n d I n t e r p r e t e r ’ , ’LaTeX ’ ) ;9 s e t ( g r o o t , ’ d e f a u l t L e g e n d F o n t S i z e ’ , 1 0 ) ;

10 s e t ( g r o o t , ’ d e f a u l t A x e s F o n t S i z e ’ , 1 2 ) ;11 s e t ( g r o o t , ’ d e f a u l t L i n e L i n e W i d t h ’ , 1 . 5 ) ;12 s e t ( g r o o t , ’ d e f a u l t F i g u r e C o l o r m a p ’ , l i n s p e c e r ) ;13

14 %P a r a m e t e r s15 T = 0 . 5 ; %u n i t s : [ s ]16 V = −6; %u n i t s : [m/ s ]17 d = 0 . 2 ; %u n i t s : [m]18

19 %I n i t i a l node P o s i t i o n and V e l o c i t y ( x , y , u , v f o r a l l n i n e nodes )20 nodes = [2* d , d , 0 , V; . . .21 3*d , d , 0 , V; . . .22 d , 2*d , 0 , V; . . .23 2*d , 2*d , 0 , V; . . .24 d , 3*d , 0 , V; . . .25 3*d , 0 , 0 , 0 ; . . .26 4*d , 0 , 0 , 0 ; . . .27 0 , 3*d , 0 , V; . . .28 0 , 4*d , 0 , V ] ;29

30 %% E i g e n v a l u e S t a b i l i t y f o r Schemes u s i n g df / du m a t r i x31 dfdu = d f d u _ m a t r i x ( nodes ) ;32

33 %Get e i g e n v a l u e s o f d f / du m a t r i x34 d f d u _ e i g = e i g ( dfdu ) ;35

A-1

Page 25: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

36 %P l o t e i g e n v a l u e s o f d f / du m a t r i x37 f i g u r e38 ho ld on39 s c a t t e r ( r e a l ( d f d u _ e i g ) , imag ( d f d u _ e i g ) , ’ o r ’ , ’ LineWidth ’ , 2 )40 a x i s e q u a l41 t i t l e ( ’ E i g e n v a l u e P l o t o f $ \ d e l t a f / \ d e l t a u$ ’ , ’ I n t e r p r e t e r ’ , ’LaTeX ’ )

;42 x l a b e l ( ’Re ( $ \ lambda \ D e l t a t $ ) ’ , ’ I n t e r p r e t e r ’ , ’LaTeX ’ ) ;43 y l a b e l ( ’ Im ( $ \ lambda \ D e l t a t $ ) ’ , ’ I n t e r p r e t e r ’ , ’LaTeX ’ ) ;44 s e t ( gcf , ’ Co lo r ’ , ’w’ , ’ P o s i t i o n ’ , [ 2 0 0 200 800 4 0 0 ] ) ;45 e x p o r t _ f i g F i g u r e s / e i g _ d f d u . eps −n a t i v e46

47 %Space o u t t h e t a v a l u e s f o r S t a b i l i t y E q u a t i o n s48 t h e t a = l i n s p a c e ( 0 , 2 * p i ) ;49

50 %E i g e n v a l u e S t a b i l i t y f o r Forward E u l e r Scheme51 lambda_dt_FE = exp (1 i . * t h e t a ) − 1 ;52

53 %S c a l e d f / du m a t r i x t o f i t i n FE Scheme E i g e n v a l u e S t a b i l i t y Region54 s c a l e F E = min ( r e a l ( d f d u _ e i g ) ) / min ( r e a l ( lambda_dt_FE ) ) ;55

56 %P l o t s c a l e d e i g e n v a l u e s t o p l o t o f s t a b l e r e g i o n57 f i g u r e58 ho ld on59 f i l l ( r e a l ( lambda_dt_FE ) , imag ( lambda_dt_FE ) , [ 1 , 1 , 1 ] , ’ F a c e c o l o r ’ , ’w’ , ’

EdgeColor ’ , ’ k ’ , ’ L i n e w i d t h ’ , 2 ) ;60 s c a t t e r ( r e a l ( d f d u _ e i g ) / sca leFE , imag ( d f d u _ e i g ) / sca leFE , ’ o r ’ , ’ LineWidth

’ , 2 )61 a x i s e q u a l62 t i t l e ( ’ E i g e n v a l u e S t a b i l i t y Region f o r Forward E u l e r u s i n g $ \ d e l t a f

/ \ d e l t a u$ ’ , ’ I n t e r p r e t e r ’ , ’LaTeX ’ ) ;63 x l a b e l ( ’Re ( $ \ lambda \ D e l t a t $ ) ’ , ’ I n t e r p r e t e r ’ , ’LaTeX ’ ) ;64 y l a b e l ( ’ Im ( $ \ lambda \ D e l t a t $ ) ’ , ’ I n t e r p r e t e r ’ , ’LaTeX ’ ) ;65 s e t ( gca , ’ Co lo r ’ , [ 0 . 8 6 2 7 0 .8627 0 . 8 6 2 7 ] )66 s e t ( gcf , ’ Co lo r ’ , ’w’ , ’ P o s i t i o n ’ , [ 2 0 0 200 800 4 0 0 ] ) ;67 e x p o r t _ f i g F i g u r e s / e ig_FE . eps −n a t i v e68

69 %Time R e s t r i c t i o n f o r Forward E u l e r70 dt_FE = 1 / s c a l e F E ;71

72 %E i g e n v a l u e S t a b i l i t y f o r AB2 Scheme73 g = exp (1 i . * t h e t a ) ;74 lambda_dt_AB2 = ( g−1) . * 2 . * g . / ( 3 . * g−1) ;75

76 %S c a l e d f / du m a t r i x t o f i t i n AdamsBashfor th Scheme E i g e n v a l u eS t a b i l i t y Region

77 scaleAB2 = min ( r e a l ( d f d u _ e i g ) ) / min ( r e a l ( lambda_dt_AB2 ) ) ;78

79 %P l o t s c a l e d e i g e n v a l u e s t o p l o t o f s t a b l e r e g i o n80 f i g u r e81 ho ld on82 f i l l ( r e a l ( lambda_dt_AB2 ) , imag ( lambda_dt_AB2 ) , [ 1 , 1 , 1 ] , ’ F a c e c o l o r ’ , ’w’ ,

’ EdgeColor ’ , ’ k ’ , ’ L i n e w i d t h ’ , 2 ) ;83 s c a t t e r ( r e a l ( d f d u _ e i g ) / scaleAB2 , imag ( d f d u _ e i g ) / scaleAB2 , ’ o r ’ , ’

LineWidth ’ , 2 )84 a x i s e q u a l85 t i t l e ( ’ E i g e n v a l u e S t a b i l i t y Region f o r Adams B a s h f o r t h u s i n g $ \ d e l t a

f / \ d e l t a u$ ’ , ’ I n t e r p r e t e r ’ , ’LaTeX ’ ) ;86 x l a b e l ( ’Re ( $ \ lambda \ D e l t a t $ ) ’ , ’ I n t e r p r e t e r ’ , ’LaTeX ’ ) ;

A-2

Page 26: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

87 y l a b e l ( ’ Im ( $ \ lambda \ D e l t a t $ ) ’ , ’ I n t e r p r e t e r ’ , ’LaTeX ’ ) ;88 s e t ( gca , ’ Co lo r ’ , [ 0 . 8 6 2 7 0 .8627 0 . 8 6 2 7 ] )89 s e t ( gcf , ’ Co lo r ’ , ’w’ , ’ P o s i t i o n ’ , [ 2 0 0 200 800 4 0 0 ] ) ;90 e x p o r t _ f i g F i g u r e s / eig_AB2 . eps −n a t i v e91

92 %Time R e s t r i c t i o n f o r RK493 dt_AB2 = 1 / scaleAB2 ;94

95 %E i g e n v a l u e S t a b i l i t y f o r RK4 Scheme96 syms lambda_d t97 lambda_dt_RK4_1 = z e r o s ( 1 , max ( s i z e ( t h e t a ) ) ) ;98 lambda_dt_RK4_2 = z e r o s ( 1 , max ( s i z e ( t h e t a ) ) ) ;99 lambda_dt_RK4_3 = z e r o s ( 1 , max ( s i z e ( t h e t a ) ) ) ;

100 lambda_dt_RK4_4 = z e r o s ( 1 , max ( s i z e ( t h e t a ) ) ) ;101

102 f o r i = 1 : max ( s i z e ( t h e t a ) )103 eqn = exp (1 i . * t h e t a ( i ) ) == 1 + lambda_d t + . 5 * lambda_d t ^2 + 1 / 6 *

lambda_d t ^3 + 1 /24* lambda_d t ^ 4 ;104 s o l = v p a s o l v e ( eqn , l ambda_d t ) ;105 lambda_dt_RK4_1 ( i ) = s o l ( 1 ) ;106 lambda_dt_RK4_2 ( i ) = s o l ( 2 ) ;107 lambda_dt_RK4_3 ( i ) = s o l ( 3 ) ;108 lambda_dt_RK4_4 ( i ) = s o l ( 4 ) ;109 end110 n = max ( s i z e ( t h e t a ) ) ;111 lambda_dt_RK4 = [ lambda_dt_RK4_1 ( 1 : ( n / 2 ) ) lambda_dt_RK4_2 ( ( ( n / 2 ) +1) :

end ) . . .112 lambda_dt_RK4_3 ( 1 : ( n / 2 ) ) lambda_dt_RK4_4 ( ( ( n / 2 ) +1) :

end ) . . .113 lambda_dt_RK4_4 ( 2 : ( n / 2 ) ) lambda_dt_RK4_3 ( ( ( n / 2 ) +1) :

end ) . . .114 lambda_dt_RK4_2 ( 2 : ( n / 2 ) ) lambda_dt_RK4_1 ( ( ( n / 2 ) +1) :

end ) ] ;115

116 %S c a l e d f / du m a t r i x t o f i t i n RK4 Scheme E i g e n v a l u e S t a b i l i t y Region117 scaleRK4 = min ( r e a l ( d f d u _ e i g ) ) / min ( r e a l ( lambda_dt_RK4 ) ) ;118

119 %P l o t s c a l e d e i g e n v a l u e s t o p l o t o f s t a b l e r e g i o n120 f i g u r e121 ho ld on122 f i l l ( r e a l ( lambda_dt_RK4 ) , imag ( lambda_dt_RK4 ) , [ 1 , 1 , 1 ] , ’ F a c e c o l o r ’ , ’w’ ,

’ EdgeColor ’ , ’ k ’ , ’ L i n e w i d t h ’ , 2 ) ;123 s c a t t e r ( r e a l ( d f d u _ e i g ) / scaleRK4 , imag ( d f d u _ e i g ) / scaleRK4 , ’ o r ’ , ’

LineWidth ’ , 2 )124 a x i s e q u a l125 t i t l e ( ’ E i g e n v a l u e S t a b i l i t y Region f o r 4 t h Order Runge−K u t t a u s i n g $ \

d e l t a f / \ d e l t a u$ ’ , ’ I n t e r p r e t e r ’ , ’LaTeX ’ ) ;126 x l a b e l ( ’Re ( $ \ lambda \ D e l t a t $ ) ’ , ’ I n t e r p r e t e r ’ , ’LaTeX ’ ) ;127 y l a b e l ( ’ Im ( $ \ lambda \ D e l t a t $ ) ’ , ’ I n t e r p r e t e r ’ , ’LaTeX ’ ) ;128 s e t ( gca , ’ Co lo r ’ , [ 0 . 8 6 2 7 0 .8627 0 . 8 6 2 7 ] )129 s e t ( gcf , ’ Co lo r ’ , ’w’ , ’ P o s i t i o n ’ , [ 2 0 0 200 800 4 0 0 ] ) ;130 e x p o r t _ f i g F i g u r e s / eig_RK4 . eps −n a t i v e131

132 %Time R e s t r i c t i o n f o r RK4133 dt_RK4 = 1 / scaleRK4 ;134

135

136 %% Hei gh t o f Lander wi th FE , AB2 , and RK4

A-3

Page 27: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

137 %Run s i m u l a t i o n wi th FE u s i n g l a r g e s t t ime s t e p wi th 3.0% a d j u s t m e n tt o

138 %p r e v e n t i n s t a b i l i t y139 dt_FE = dt_FE * 0 . 9 7 ;140 t_FE = 0 : dt_FE : T ;141 nodeSpaceFE = FE ( nodes , t_FE ) ;142 h_FE = nodeSpaceFE ( 3 0 , : ) ;143

144 %F i n a l R e s u l t f o r V e r i f i c a t i o n145 n o d e s F E _ f i n a l = nodeSpace2nodes ( nodeSpaceFE ) ;146 f i g u r e147 p l o t N o d e s ( n o d e s F E _ f i n a l , T ) ;148 e x p o r t _ f i g ’ F i g u r e s / f i n a l _ F E . eps ’149

150 %Run s i m u l a t i o n wi th AB2 u s i n g l a r g e s t t ime s t e p wi th 3.0% a d j u s t m e n tt o

151 %p r e v e n t i n s t a b i l i t y152 dt_AB2 = dt_AB2 * 0 . 9 7 ;153 t_AB2 = 0 : dt_AB2 : T ;154 nodeSpaceAB2 = AB2( nodes , t_AB2 ) ;155 h_AB2 = nodeSpaceAB2 ( 3 0 , : ) ;156

157 %F i n a l R e s u l t f o r V e r i f i c a t i o n158 nodesAB2_f ina l = nodeSpace2nodes ( nodeSpaceAB2 ) ;159 f i g u r e160 p l o t N o d e s ( nodesAB2_f ina l , T ) ;161 e x p o r t _ f i g ’ F i g u r e s / f ina l_AB2 . eps ’162

163 %Run s i m u l a t i o n wi th RK4 u s i n g l a r g e s t t ime s t e p wi th 3.0% a d j u s t m e n tt o

164 %p r e v e n t i n s t a b i l i t y165 dt_RK4 = dt_RK4 * 0 . 9 7 ;166 t_RK4 = 0 : dt_RK4 : T ;167 nodeSpaceRK4 = RK4( nodes , t_RK4 ) ;168 h_RK4 = nodeSpaceRK4 ( 3 0 , : ) ;169

170 %F i n a l R e s u l t f o r V e r i f i c a t i o n171 nodesRK4_f ina l = nodeSpace2nodes ( nodeSpaceRK4 ) ;172 f i g u r e173 p l o t N o d e s ( nodesRK4_f ina l , T ) ;174 e x p o r t _ f i g ’ F i g u r e s / f ina l_RK4 . eps ’175

176 f i g u r e177 axes ( ’ N e x t P l o t ’ , ’ r e p l a c e c h i l d r e n ’ , ’ C o l o r O r d e r ’ , l i n s p e c e r ( 3 ) ) ;178 s e m i l o g y ( t_FE , h_FE , t_AB2 , h_AB2 , t_RK4 , h_RK4 , ’−− ’ , ’ L i n e w i d t h ’ , 2 ) ;179 t i t l e ( ’ He i gh t o f Lunar Lander ( Node 8) u s i n g D i f f e r e n t Numer ica l

Schemes wi th U n s t a b l e Time−S t e p s ’ ) ;180 l e g e n d ( ’ Forward E u l e r Numer ica l S o l u t i o n ’ , ’Adams B a s h f o r t h Numer ica l

S o l u t i o n ’ , ’ 4 t h Order Runge−K u t t a Numer ica l S o l u t i o n ’ , ’ L o c a t i o n ’ , ’Bes t ’ )

181 x l a b e l ( ’ Time [ s ] ’ ) ;182 y l a b e l ( ’ He i gh t o f Lunar Lander ( Node 8) [m] ’ ) ;183 s e t ( gcf , ’ Co lo r ’ , ’w’ , ’ P o s i t i o n ’ , [ 2 0 0 200 900 4 0 0 ] ) ;184 e x p o r t _ f i g F i g u r e s / l a n d e r _ h e i g h t . eps −n a t i v e185

186 %% S i m u l a t i o n s wi th FE , AB2 , and RK4 up t o T = 0 . 5187

188 %I n i t i a l Node P o s i t i o n189 f i g u r e

A-4

Page 28: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

190 p l o t N o d e s ( nodes , 0 ) ;191

192 %RK4 S i m u l a t i o n f o r T = 0 . 5 a t v a r y i n g t i m e s193 t i m e s = 0 . 0 5 : 0 . 0 5 : 0 . 5 ;194 s e t ( 0 , ’ D e f a u l t F i g u r e V i s i b l e ’ , ’ o f f ’ )195 f o r i = 1 : max ( s i z e ( t i m e s ) )196 nodeSpaceRK4 = RK4( nodes , 0 : dt_RK4 : t i m e s ( i ) ) ;197 nodesRK4 = nodeSpace2nodes ( nodeSpaceRK4 ) ;198 f i g u r e199 p l o t N o d e s ( nodesRK4 , t i m e s ( i ) ) ;200 end201 s e t ( 0 , ’ D e f a u l t F i g u r e V i s i b l e ’ , ’ on ’ )202

203 %% E r r o r A n a l y s i s204

205 %F i r s t run RK4 wi th h igh r e s o l u t i o n t o d e f i n e " c o r r e c t " answer f o rh e i g h t a t

206 %T = 5 ;207 t_RK4 = l i n s p a c e ( 0 , T , 1 0 0 0 0 0 ) ;208 %nodeSpaceRK4 = RK4( nodes , t_RK4 ) ; d i s a b l e d f o r t ime r e a o n s209 nodeSpaceRK4 = c e l l 2 m a t ( s t r u c t 2 c e l l ( l o a d ( ’ R K 4 _ f i n e _ s i m u l a t i o n . mat ’ ) ) )

;210 h _ a c t u a l = nodeSpaceRK4 ( 3 0 , : ) ;211 h _ a c t u a l = h _ a c t u a l ( end ) ;212

213 %Three Time S t e p s214 t_3_FE = 0 : 2 . 2 4 1 1 e−4:T ;215 t_3_AB2 = 0 : 1 . 1 3 3 e−4:T ;216 t_3_RK4 = 0 : 2 . 5 e−4:T ;217 t _ 2 = 0 : 0 . 0 0 0 1 : T ;218 t _ 1 = 0 : 0 . 0 0 0 0 5 : T ;219

220 %FE E r r o r C a l c u l a t i o n s a t Three P o i n t s221 nodeSpaceFE_3 = FE ( nodes , t_3_FE ) ;222 h_FE_3 = nodeSpaceFE_3 ( 3 0 , : ) ;223 e r r o r _ F E _ 3 = abs ( h _ a c t u a l − h_FE_3 ( end ) ) ;224

225 nodeSpaceFE_2 = FE ( nodes , t _ 2 ) ;226 h_FE_2 = nodeSpaceFE_2 ( 3 0 , : ) ;227 e r r o r _ F E _ 2 = abs ( h _ a c t u a l − h_FE_2 ( end ) ) ;228

229 nodeSpaceFE_1 = FE ( nodes , t _ 1 ) ;230 h_FE_1 = nodeSpaceFE_1 ( 3 0 , : ) ;231 e r r o r _ F E _ 1 = abs ( h _ a c t u a l − h_FE_1 ( end ) ) ;232

233 %AB2 E r r o r C a l c u l a t i o n s a t Three P o i n t s234 nodeSpaceAB2_3 = AB2( nodes , t_3_AB2 ) ;235 h_AB2_3 = nodeSpaceAB2_3 ( 3 0 , : ) ;236 error_AB2_3 = abs ( h _ a c t u a l − h_AB2_3 ( end ) ) ;237

238 nodeSpaceAB2_2 = AB2( nodes , t _ 2 ) ;239 h_AB2_2 = nodeSpaceAB2_2 ( 3 0 , : ) ;240 error_AB2_2 = abs ( h _ a c t u a l − h_AB2_2 ( end ) ) ;241

242 nodeSpaceAB2_1 = AB2( nodes , t _ 1 ) ;243 h_AB2_1 = nodeSpaceAB2_1 ( 3 0 , : ) ;244 error_AB2_1 = abs ( h _ a c t u a l − h_AB2_1 ( end ) ) ;245

246 %RK4 E r r o r C a l c u l a t i o n s a t Three P o i n t s

A-5

Page 29: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

247 nodeSpaceRK4_3 = RK4( nodes , t_3_RK4 ) ;248 h_RK4_3 = nodeSpaceRK4_3 ( 3 0 , : ) ;249 error_RK4_3 = abs ( h _ a c t u a l − h_RK4_3 ( end ) ) ;250

251 nodeSpaceRK4_2 = RK4( nodes , t _ 2 ) ;252 h_RK4_2 = nodeSpaceRK4_2 ( 3 0 , : ) ;253 error_RK4_2 = abs ( h _ a c t u a l − h_RK4_2 ( end ) ) ;254

255 nodeSpaceRK4_1 = RK4( nodes , t _ 1 ) ;256 h_RK4_1 = nodeSpaceRK4_1 ( 3 0 , : ) ;257 error_RK4_1 = abs ( h _ a c t u a l − h_RK4_1 ( end ) ) ;258

259 %Put t ime s t e p s i n v e c t o r f o r p l o t t i n g260 t i m e s t e p s F E = [ 2 . 2 4 1 1 e−4 0 .0001 0 . 0 0 0 0 5 ] ;261 t imes tepsAB2 = [ 1 . 1 3 3 e−4 0 .0001 0 . 0 0 0 0 5 ] ;262 t imes tepsRK4 = [ 2 . 5 e−4 0 .0001 0 . 0 0 0 0 5 ] ;263

264 %C a l c u l a t e S lope on Loglog P l o t265 s lope_FE = log10 ( e r r o r _ F E _ 2 / e r r o r _ F E _ 1 ) / log10 ( 0 . 0 0 0 1 / 0 . 0 0 0 0 5 ) ;266 slope_AB2 = log10 ( error_AB2_2 / error_AB2_1 ) / log10 ( 0 . 0 0 0 1 / 0 . 0 0 0 0 5 ) ;267 slope_RK4 = log10 ( error_RK4_2 / error_RK4_1 ) / log10 ( 0 . 0 0 0 1 / 0 . 0 0 0 0 5 ) ;268

269 f i g u r e270 axes ( ’ N e x t P l o t ’ , ’ r e p l a c e c h i l d r e n ’ , ’ C o l o r O r d e r ’ , l i n s p e c e r ( 3 ) ) ;271 l o g l o g ( t i m e s t e p s F E , [ e r r o r _ F E _ 3 e r r o r _ F E _ 2 e r r o r _ F E _ 1 ] , t imes tepsAB2 , [

er ror_AB2_3 error_AB2_2 error_AB2_1 ] , t imes tepsRK4 , [ error_RK4_3error_RK4_2 error_RK4_1 ] ) ;

272 t i t l e ( ’ Convergence Study i n D i f f e r i n g S o l u t i o n Methods f o r LunarLander T r u s s ’ , ’ I n t e r p r e t e r ’ , ’LaTeX ’ ) ;

273 x l a b e l ( ’ Time S tep ( $ \ D e l t a t $ ) [ s ] ’ , ’ I n t e r p r e t e r ’ , ’LaTeX ’ ) ;274 y l a b e l ( ’ E r r o r i n He i gh t from P r e c i s e RK4 S o l u t i o n [m] ’ , ’ I n t e r p r e t e r ’

, ’LaTeX ’ ) ;275 l e g e n d ( [ ’ Forward E u l e r ( FE ) : ’ , num2s t r ( s lope_FE ) ] , [ ’Adams B a s h f o r t h

(AB2) : ’ , num2s t r ( slope_AB2 ) ] , [ ’ Runge−K u t t a (RK4) : ’ , num2s t r (slope_RK4 ) ] , ’ I n t e r p r e t e r ’ , ’LaTeX ’ , ’ L o c a t i o n ’ , ’ S o u t h e a s t ’ ) ;

276 g r i d on277 g r i d minor278 s e t ( gcf , ’ Co lo r ’ , ’w’ , ’ P o s i t i o n ’ , [ 2 0 0 200 1000 4 0 0 ] ) ;279 e x p o r t _ f i g F i g u r e s / l a n d e r _ e r r o r . eps −n a t i v e

Algorithm 1: MATLAB Script used to call implemented functions.

A-6

Page 30: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

A.3 MATLAB Function Implementation

1 f u n c t i o n nodes = nodeSpace2nodes ( nodeSpace )2 %Conver t column s t a t e s p a c e v e c t o r t o node m a t r i x i n o r d e r t o

p l o t3 nodes = [ nodeSpace ( 1 : 4 , l e n g t h ( nodeSpace ) ) ’ ; nodeSpace ( 5 : 8 , l e n g t h (

nodeSpace ) ) ’ ; nodeSpace ( 9 : 1 2 , l e n g t h ( nodeSpace ) ) ’ ; nodeSpace( 1 3 : 1 6 , l e n g t h ( nodeSpace ) ) ’ ; nodeSpace ( 1 7 : 2 0 , l e n g t h ( nodeSpace ) ) ’ ;. . .

4 nodeSpace ( 2 1 : 2 4 , l e n g t h ( nodeSpace ) ) ’ ; nodeSpace ( 2 5 : 2 8 ,l e n g t h ( nodeSpace ) ) ’ ; nodeSpace ( 2 9 : 3 2 , l e n g t h ( nodeSpace ) ) ’ ;nodeSpace ( 3 3 : 3 6 , l e n g t h ( nodeSpace ) ) ’ ] ;

5 end

Algorithm 2: Function responsible for converting column space vector into node matrix

1 f u n c t i o n dfdu = d f d u _ m a t r i x ( nodes )2 %Smal l P e r t u r b a t i o n3 h = 1e−6;4 %P r e a l l o c a t e 22 x22 Ma t r i x5 dfdu = z e r o s ( 2 2 ) ;6 %Take i n i t i a l d e r i v a t i v e7 f_0 = f ( nodes ) ;8 %Begin a r r a y i n d e x i n g9 n = 1 ;

10 f o r i = 1 : 511 f o r j = 1 : 412 %S t o r e node i n p u t a s t e m p o r a r y t o keep i t from ch a n g i n g

a t13 %e v e r y i t e r a t i o n14 node_temp = nodes ;15 %Add p e r t u r b a t i o n t o temp node m a t r i x16 node_temp ( i , j ) = node_temp ( i , j ) + h ;17 %Put temp node m a t r i x i n t o f f u n c t i o n18 df = f ( node_temp ) ;19 %Take d e r i v a t i v e u s i n g c l a s s i c e q u a t i o n wi th h

p e r t u r b a t i o n20 dfdu ( : , n ) = ( d f ( 1 : 2 2 ) − f_0 ( 1 : 2 2 ) ) / h ;21 n = n + 1 ;22 end23 end24 end

Algorithm 3: Function responsible for outputing Jacobian matrix

A-7

Page 31: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

1 f u n c t i o n o u t p u t = RK4( nodes , t )2 %Setup RK43 d t = t ( 2 ) − t ( 1 ) ;4 u = z e r o s ( max ( s i z e ( nodes ) ) *min ( s i z e ( nodes ) ) , max ( s i z e ( t ) ) ) ;5 N = max ( s i z e ( t ) ) ;6

7 %O r g a n i z e column v e c t o r from node m a t r i x8 u ( : , 1 ) = [ nodes ( 1 , : ) ’ ; nodes ( 2 , : ) ’ ; nodes ( 3 , : ) ’ ; nodes ( 4 , : ) ’ ;

nodes ( 5 , : ) ’ ; nodes ( 6 , : ) ’ ; nodes ( 7 , : ) ’ ; nodes ( 8 , : ) ’ ; nodes ( 9 , : ) ’ ] ;9

10 %Perform RK4 method u s i n g column v e c t o r form11 f o r i = 1 : ( N−1)12 temp = [ u ( 1 : 4 , i ) ’ ; u ( 5 : 8 , i ) ’ ; u ( 9 : 1 2 , i ) ’ ; u ( 1 3 : 1 6 , i ) ’ ; u

( 1 7 : 2 0 , i ) ’ ; . . .13 u ( 2 1 : 2 4 , i ) ’ ; u ( 2 5 : 2 8 , i ) ’ ; u ( 2 9 : 3 2 , i ) ’ ; u ( 3 3 : 3 6 , i ) ’ ] ;14 k_0 = f ( temp ) ;15

16 temp_k_1 = [ k_0 ( 1 : 4 ) ’ ; k_0 ( 5 : 8 ) ’ ; k_0 ( 9 : 1 2 ) ’ ; k_0 ( 1 3 : 1 6 ) ’ ;k_0 ( 1 7 : 2 0 ) ’ ; . . .

17 k_0 ( 2 1 : 2 4 ) ’ ; k_0 ( 2 5 : 2 8 ) ’ ; k_0 ( 2 9 : 3 2 ) ’ ; k_0 ( 3 3 : 3 6 ) ’ ] ;18 k_1 = f ( temp + 0 . 5 . * d t . * temp_k_1 ) ;19

20 temp_k_2 = [ k_1 ( 1 : 4 ) ’ ; k_1 ( 5 : 8 ) ’ ; k_1 ( 9 : 1 2 ) ’ ; k_1 ( 1 3 : 1 6 ) ’ ;k_1 ( 1 7 : 2 0 ) ’ ; . . .

21 k_1 ( 2 1 : 2 4 ) ’ ; k_1 ( 2 5 : 2 8 ) ’ ; k_1 ( 2 9 : 3 2 ) ’ ; k_1 ( 3 3 : 3 6 ) ’ ] ;22 k_2 = f ( temp + 0 . 5 . * d t . * temp_k_2 ) ;23

24 temp_k_3 = [ k_2 ( 1 : 4 ) ’ ; k_2 ( 5 : 8 ) ’ ; k_2 ( 9 : 1 2 ) ’ ; k_2 ( 1 3 : 1 6 ) ’ ;k_2 ( 1 7 : 2 0 ) ’ ; . . .

25 k_2 ( 2 1 : 2 4 ) ’ ; k_2 ( 2 5 : 2 8 ) ’ ; k_2 ( 2 9 : 3 2 ) ’ ; k_2 ( 3 3 : 3 6 ) ’ ] ;26 k_3 = f ( temp + d t . * temp_k_3 ) ;27

28 u ( : , i +1) = u ( : , i ) + d t / 6 . * ( k_0 + 2 . * k_1 + 2 . * k_2 + k_3 ) ;29 end30

31 %o u t p u t i s m a t r i x o f x1 y1 v1 u1 f o r each node i n column form f o reach

32 %time s t e p33 o u t p u t = u ;34 end

Algorithm 4: Function responsible for Runge-Kutta Implementation

A-8

Page 32: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

1 f u n c t i o n o u t p u t = AB2( nodes , t )2 %Setup method3 d t = t ( 2 ) − t ( 1 ) ;4 u = z e r o s ( max ( s i z e ( nodes ) ) *min ( s i z e ( nodes ) ) , max ( s i z e ( t ) ) ) ;5 N = max ( s i z e ( t ) ) ;6

7 %O r g a n i z e column v e c t o r from node m a t r i x8 u ( : , 1 ) = [ nodes ( 1 , : ) ’ ; nodes ( 2 , : ) ’ ; nodes ( 3 , : ) ’ ; nodes ( 4 , : ) ’ ;

nodes ( 5 , : ) ’ ; nodes ( 6 , : ) ’ ; nodes ( 7 , : ) ’ ; nodes ( 8 , : ) ’ ; nodes ( 9 , : ) ’ ] ;9 temp = [ u ( 1 : 4 , 1 ) ’ ; u ( 5 : 8 , 1 ) ’ ; u ( 9 : 1 2 , 1 ) ’ ; u ( 1 3 : 1 6 , 1 ) ’ ; u ( 1 7 : 2 0 , 1 )

’ ; . . .10 u ( 2 1 : 2 4 , 1 ) ’ ; u ( 2 5 : 2 8 , 1 ) ’ ; u ( 2 9 : 3 2 , 1 ) ’ ; u ( 3 3 : 3 6 , 1 ) ’ ] ;11

12 %Take i n i t i a l s t e p u s i n g Forward E u l e r13 u ( : , 2 ) = u ( : , 1 ) + d t . * f ( temp ) ;14

15 %Perform AB2 method u s i n g column v e c t o r form16 f o r i = 2 : ( N−1)17 temp1 = temp ;18 temp = [ u ( 1 : 4 , i ) ’ ; u ( 5 : 8 , i ) ’ ; u ( 9 : 1 2 , i ) ’ ; u ( 1 3 : 1 6 , i ) ’ ; u

( 1 7 : 2 0 , i ) ’ ; . . .19 u ( 2 1 : 2 4 , i ) ’ ; u ( 2 5 : 2 8 , i ) ’ ; u ( 2 9 : 3 2 , i ) ’ ; u ( 3 3 : 3 6 , i ) ’ ] ;20 u ( : , i +1) = u ( : , i ) + d t . * ( 1 . 5 . * f ( temp ) − . 5 . * f ( temp1 ) ) ;21 end22

23 %o u t p u t i s m a t r i x o f x1 y1 v1 u1 f o r each node i n column form f o reach

24 %time s t e p25 o u t p u t = u ;26 end

Algorithm 5: Function responsible for Adams Bashforth Implementation

1 f u n c t i o n o u t p u t = FE ( nodes , t )2 %Setup Forward E u l e r3 d t = t ( 2 ) − t ( 1 ) ;4 u = z e r o s ( max ( s i z e ( nodes ) ) *min ( s i z e ( nodes ) ) , max ( s i z e ( t ) ) ) ;5 N = max ( s i z e ( t ) ) ;6

7 %O r g a n i z e node m a t r i x i n t o column v e c t o r8 u ( : , 1 ) = [ nodes ( 1 , : ) ’ ; nodes ( 2 , : ) ’ ; nodes ( 3 , : ) ’ ; nodes ( 4 , : ) ’ ;

nodes ( 5 , : ) ’ ; nodes ( 6 , : ) ’ ; nodes ( 7 , : ) ’ ; nodes ( 8 , : ) ’ ; nodes ( 9 , : ) ’ ] ;9

10 %Implement Forward E u l e r Scheme11 f o r i = 1 : ( N−1)12 temp = [ u ( 1 : 4 , i ) ’ ; u ( 5 : 8 , i ) ’ ; u ( 9 : 1 2 , i ) ’ ; u ( 1 3 : 1 6 , i ) ’ ; u

( 1 7 : 2 0 , i ) ’ ; . . .13 u ( 2 1 : 2 4 , i ) ’ ; u ( 2 5 : 2 8 , i ) ’ ; u ( 2 9 : 3 2 , i ) ’ ; u ( 3 3 : 3 6 , i ) ’ ] ;14 u ( : , i +1) = u ( : , i ) + d t . * f ( temp ) ;15 end16

17 %o u t p u t i s m a t r i x o f x1 y1 v1 u1 f o r each node i n column form f o reach

18 %time s t e p19 o u t p u t = u ;20 end

Algorithm 6: Function responsible for Forward Euler Implementation

A-9

Page 33: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

1 f u n c t i o n udo t = f ( nodes )2 %C o n s t a n t s3 m_node = 0 . 1 ;4 M = 100 ;5 g = 1 . 6 2 5 ;6

7 %E q u a t i o n o f Mot ions f o r a l l n i n e nodes o r g a n i z e d i n t o u , v , d o t u ,and d o t v form

8 udo t = [ [ nodes ( 1 , 3 : 4 ) ’ ; n o d e _ f o r c e ( nodes , 1 ) ’ / m_node ] − [0 0 0 g] ’ ;

9 [ nodes ( 2 , 3 : 4 ) ’ ; n o d e _ f o r c e ( nodes , 2 ) ’ / m_node ] − [0 0 0 g] ’ ;

10 [ nodes ( 3 , 3 : 4 ) ’ ; n o d e _ f o r c e ( nodes , 3 ) ’ / m_node ] − [0 0 0 g] ’ ;

11 [ nodes ( 4 , 3 : 4 ) ’ ; n o d e _ f o r c e ( nodes , 4 ) ’ / m_node ] − [0 0 0 g] ’ ;

12 [ nodes ( 5 , 3 : 4 ) ’ ; n o d e _ f o r c e ( nodes , 5 ) ’ / m_node ] − [0 0 0 g] ’ ;

13 [0 0 0 0 ] ’ ;14 [0 0 0 0 ] ’ ;15 ( [ ( nodes ( 9 , 3 : 4 ) ) ’ . * [ 0 ; 1 ] ; 8 . * ( n o d e _ f o r c e ( nodes , 8 ) . /M) ’

. * [ 0 ; 1 ] ] − [0 0 0 g ] ’ ) ;16 ( [ ( nodes ( 9 , 3 : 4 ) ) ’ . * [ 0 ; 1 ] ; 8 . * ( n o d e _ f o r c e ( nodes , 9 ) . /M) ’

. * [ 0 ; 1 ] ] − [0 0 0 g ] ’ ) ] ;17 end

Algorithm 7: Function responsible for output of accelerlation and velocity state space

1 f u n c t i o n sum = n o d e _ f o r c e ( nodes , node )2 %C o n s t a n t s3 gamma = 200 ;4 k = 1 0^ 5 ;5 sum = [0 0 ] ;6 %Each node (1−9) wi th c o n n e c t i o n s7 l i n k s = [2 3 4 6 ;8 1 6 4 7 ;9 1 4 5 8 ;

10 1 2 3 5 ;11 3 4 8 9 ;12 1 2 NaN NaN ;13 2 NaN NaN NaN ;14 3 5 NaN NaN ;15 5 NaN NaN NaN ] ;16

17 %T e s t i f c o n n e c t i n g node e x i s t s t o g i v e n node , and i f i t doesloop

18 %t h r o u g h t o g a t h e r a l l f o r c e s19 f o r i = 1 : max ( s i z e ( nodes ) )20 i f ismember ( node , l i n k s ( i , : ) ) == 121 i f ( node == 1 && ( i == 2 | | i == 4) )22 d = 0 . 2 ;23 e l s e i f ( node == 2 && ( i == 6 | | i == 1) )24 d = 0 . 2 ;25 e l s e i f ( node == 3 && ( i == 4 | | i == 5) )26 d = 0 . 2 ;27 e l s e i f ( node == 4 && ( i == 3 | | i == 1) )28 d = 0 . 2 ;29 e l s e i f ( node == 5 && ( i == 3 | | i == 8) )

A-10

Page 34: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

30 d = 0 . 2 ;31 e l s e i f ( node == 6 && ( i == 2) )32 d = 0 . 2 ;33 e l s e i f ( node == 8 && ( i == 5) )34 d = 0 . 2 ;35 e l s e36 d = 0 . 2 * s q r t ( 2 ) ;37 end38

39 %E q u a t i o n f o r l i n k f o r c e s from p r o j e c t s t a t e m e n t40 x1 = nodes ( node , 1 : 2 ) ;41 x2 = nodes ( i , 1 : 2 ) ;42

43 v1 = nodes ( node , 3 : 4 ) ;44 v2 = nodes ( i , 3 : 4 ) ;45

46 e = ( x2 − x1 ) . / norm ( x2 − x1 ) ;47

48 %D e l t a l49 d l = norm ( x2 − x1 ) − d ;50 d l ( abs ( d l ) < 1e−16) = 0 ;51

52 %Dot D e l t a l53 d d l = d o t ( ( v2 − v1 ) , e ) ;54 d d l ( abs ( d d l ) < 1e−16) = 0 ;55

56 F i j = ( k . * d l + gamma . * d d l ) . * e ;57

58 %Sum a l l f o r c e s59 i f ( norm ( F i j ) > 1e−16)60 sum = sum + F i j ;61 end62 end63 end64 end

Algorithm 8: Function responsible for summation of forces on a node

A-11

Page 35: Lunar Lander Truss Project - University of Michigan

Drake RundellAERO 423

Lunar Lander Truss Project

1 f u n c t i o n p l o t N o d e s ( nodes , t )2 %Make each l i n k3 L_72 = [ nodes ( 7 , 1 : 2 ) ; nodes ( 2 , 1 : 2 ) ] ;4 L_62 = [ nodes ( 6 , 1 : 2 ) ; nodes ( 2 , 1 : 2 ) ] ;5 L_12 = [ nodes ( 1 , 1 : 2 ) ; nodes ( 2 , 1 : 2 ) ] ;6 L_42 = [ nodes ( 4 , 1 : 2 ) ; nodes ( 2 , 1 : 2 ) ] ;7 L_13 = [ nodes ( 1 , 1 : 2 ) ; nodes ( 3 , 1 : 2 ) ] ;8 L_16 = [ nodes ( 1 , 1 : 2 ) ; nodes ( 6 , 1 : 2 ) ] ;9 L_14 = [ nodes ( 1 , 1 : 2 ) ; nodes ( 4 , 1 : 2 ) ] ;

10 L_43 = [ nodes ( 4 , 1 : 2 ) ; nodes ( 3 , 1 : 2 ) ] ;11 L_45 = [ nodes ( 4 , 1 : 2 ) ; nodes ( 5 , 1 : 2 ) ] ;12 L_35 = [ nodes ( 3 , 1 : 2 ) ; nodes ( 5 , 1 : 2 ) ] ;13 L_38 = [ nodes ( 3 , 1 : 2 ) ; nodes ( 8 , 1 : 2 ) ] ;14 L_59 = [ nodes ( 5 , 1 : 2 ) ; nodes ( 9 , 1 : 2 ) ] ;15 L_58 = [ nodes ( 5 , 1 : 2 ) ; nodes ( 8 , 1 : 2 ) ] ;16

17 %O r g a n i z e i n t o x and y s p a c e18 x = [ L_72 ( : , 1 ) L_62 ( : , 1 ) L_12 ( : , 1 ) L_42 ( : , 1 ) L_13 ( : , 1 ) L_16 ( : , 1 )

. . .19 L_14 ( : , 1 ) L_43 ( : , 1 ) L_45 ( : , 1 ) L_35 ( : , 1 ) L_38 ( : , 1 ) L_59 ( : , 1 )

L_58 ( : , 1 ) ] ;20 y = [ L_72 ( : , 2 ) L_62 ( : , 2 ) L_12 ( : , 2 ) L_42 ( : , 2 ) L_13 ( : , 2 ) L_16 ( : , 2 )

. . .21 L_14 ( : , 2 ) L_43 ( : , 2 ) L_45 ( : , 2 ) L_35 ( : , 2 ) L_38 ( : , 2 ) L_59 ( : , 2 )

L_58 ( : , 2 ) ] ;22

23 axes ( ’ N e x t P l o t ’ , ’ r e p l a c e c h i l d r e n ’ , ’ C o l o r O r d e r ’ , l i n s p e c e r ( max ( s i z e( x ) ) *7) ) ;

24 p l o t ( x , y , ’−o ’ )25 t i t l e ( ’ Lunar Lander T r u s s i n 2D Space ’ ) ;26 x l a b e l ( ’ x P o s i t i o n (m) ’ ) ;27 y l a b e l ( ’ y P o s i t i o n (m) ’ ) ;28 xl im ( [ 0 0 . 8 ] ) ;29 yl im ( [ 0 1 ] ) ;30 s e t ( gcf , ’ Co lo r ’ , ’w’ , ’ P o s i t i o n ’ , [ 2 0 0 200 400 4 0 0 ] ) ;31 t e x t ( 0 . 4 , 0 . 8 , [ ’ t = ’ num2s t r ( t ) ’ s ’ ] , ’ F o n t s i z e ’ , 1 2 , ’ I n t e r p r e t e r ’

, ’LaTeX ’ ) ;32 e x p o r t _ f i g ( [ ’ F i g u r e s / l a n d e r _ t r u s s _ t _ ’ , num2s t r ( t *100) , ’ . eps ’ ] )33 end

Algorithm 9: Function responsible for plotting truss layout in 2D

A-12