##### Reference no: EM131097933

**E19: Numerical Methods for Engineering Applications Spring 2016 - PROJECT 5**

**Project: Numerical approximation of ODE's - Roller Coaster Simulation**

OVERVIEW

In this project, you will simulate the motion of a roller coaster along a parametrically defined track, in order to investigate Lagrangian mechanics and accuracy of different numerical methods for approximating solutions of ordinary differential equations (ODE's).

BACKGROUND

In class, we examined using Lagrangian mechanics to derive the equations of motion for a dynamical system. We begin by defining q, the vector of n generalized position coordinates for the system (typically one per degree of freedom of the system). The Lagrangian of a conservative (energy-preserving) system is defined to be

L(q, q^{·}) = T(q, q^{·}) - V(q)

where T(q, q^{·}) is the kinetic energy, and V(q) is the potential energy. The Euler-Lagrange equation states that for each element q_{i} of the generalized coordinates,

(d/dt)(∂L/∂q^{·}_{i}) - (∂L/∂q_{i}) = 0

which gives n second-order differential equations in the elements of q.

We then transform the resulting differential equations into a set of 2n equations by defining y to be the state vector of the system consisting of both positions and velocities, with

and subsequently numerically solving the ODE system

y^{·} = f(t, y)

where the first n elements of f return the generalized velocities, and the second n elements compute the generalized accelerations computed by the Euler-Lagrange equation.

**TASKS**

In class, we examined the case where the "roller coaster" is defined as a function f(x), with the single generalized position coordinate q = x. Unfortunately, this parameterization of the problem is ill-equipped to handle vertical loops (a.k.a. loop-de-loops).

Define an alternative parameterization in terms of a single position coordinate q = u, with both the x- and y-coordinates of the roller coaster given by two parametric functions x(u) and y(u), and derive the corresponding equations of motion by forming the Euler-Lagrange equation for the new system and solving for u^{··} in terms of the parametric functions and their derivatives.

Design a roller coaster by defining the two functions x(u) and y(u). You should use the cubic spline solver you developed in project 2 to define these functions in order to design your track. Note that you will need to be able to evaluate not only the position of each spline, but also their derivatives.

Your roller coaster must include at least two hills and one vertical loop. Assume that both x and y are expressed in meters, and design your roller coaster to have a plausible physical scale. You should set the initial conditions such that the roller coaster has enough energy to get from u = 0 to the end of the roller coaster.

Simulate your roller coaster by using both Euler's method, a second order method such as Heun's method or the midpoint method, and the fourth order RK method given in Homework 10. Simulate each algorithm using a timestep of 0.01s and 0.001s, for a total of six simulation runs.

Your program should be able to generate animations of the simulation result of each method. To prevent excessively large animations, only produce an animated frame for every fourth step when using 0.01s timesteps, and every 40 steps for 0.001s (i.e., your animations should run in realtime at 25 FPS). You should look at the pendulum_2d_demo.py example in the starter code to see an example animation. Feel free to get creative about what you visualize, but at minimum, I'd like to see a plot of the "car" moving along the track with a unit aspect ratio (so that both x and y are drawn to scale).

**WHAT TO TURN IN**

You should submit all of your source code along with a PDF write-up addressing the following:

- Show that your solution to the Euler-Lagrange equation is a generalization of the case we derived in class (or in the _test_roller_coaster_func() method in LagrangianMechanics.py. What are the corresponding functions for x(u) and y(u) in the simpler case?
- For each numerical integration scheme and step size, produce a plot graphing the kinetic energy, potential energy, and total energy (i.e. their sum) over time. You should have 6 plots with three traces each.
- Noting that the total energy should be constant over time (since the system is conservative), interpret the plots in terms of the effectiveness of each integration scheme and stepsize.
- Include remarks on any unexpected or surprising behavior of your simulations, as well as any pitfalls you encountered in implementing this project.

**Attachment:-** Assignment.zip