Skateboard on a half-pipe

Here are my notes on example 1.2 and problem 1.50: https://people.goshen.edu/~paulmr/physix/302/gco/1.6.php

I adapted material from this documentation of Sagemath: http://doc.sagemath.org/html/en/reference/calculus/sage/calculus/desolvers.html

We came up with this differential equation for the polar angle, $\phi$, of the skateboard on the half-pipe: $$\ddot \phi(t)=-\frac gR \sin\phi(t)$$ Unfortunately, this is a non-linear differential equation with no exact solution.

Using the small angle approximation, $\sin\phi\approx\phi$, We get this approximate equation of motion $$\ddot \phi(t)\approx -\frac gR \phi(t)$$ which does have an exact solution.

We can also solve the original, non-linear diff eq numerically, which we'll do, and then compare to the approximate solution.


Solving the approximate differential equation

We want to solve the approximate differential equation exactly

$$\frac{d^2\phi(t)}{dt^2}= -\frac gR \phi(t).$$

Subject to these initial conditions:

  • at $t=0,
  • the skateboard starts at an angle (radians) of \phi(0)=\phi_0,
  • the skateboard starts from rest: $ \phi'(0)=0$

Below, I'm going to write $\phi_0$ as p0. And I'll write the parameter combination $g/R$ as g_o_R.

In [1]:
# declare all variables / parameters
t,g_o_R,p0=var('t g_o_R p0')

# Make these distinctive numbers, so we can pick them out of the solution
p0=0.37
g_o_R=13

# declare phi to be a function of t
phi = function('phi')(t)

# assign the differential equation to be solved to the name "diffeq"
diffeq = diff(phi,t,2)== -g_o_R*phi #that is, phi''(t) = -(g/R)*phi(t) !


# desolve solves 'diffeq' for the function 'phi'
#   ics mean initial conditions. For our 2nd order DE, these can be [t0, phi(t_0), phi'(t_0)]
#   ivar means the name of the independent variable
h = desolve(diffeq, phi, ics=[0,p0,0],ivar=t)
show(h)

# the output of desolve is phi(t):
Out[1]:

This means that our solution is: $$\phi(t)=\phi_0\cos\left( \sqrt{\frac gR} t\right).$$


Solving the approximate differential equation (2nd order) as a set of coupled first order equations exactly

Most of SageMath's numerical routines operate on systems of first order differential equations. So, our first step is to convert our 2nd order diff eq into coupled first order diff eqs. First we'll solve the coupled differential equations exactly, and check that we get the same solution above

Set up these functions: $$\phi(t)=x_1(t);\ \phi'(t)=x_2(t)$$ And then $x_2'(t)=\phi''(t)$. We can now re-write $\phi''(t)= -\frac gR \phi(t).$ as the two equations: $$x_1'(t) = x_2(t)$$ $$x_2'(t)= -\frac gR x_1(t)$$ The initial conditions are now $$\phi(0)=p_0=x_1(0)$$ $$\phi'(0)=0=x_2(0)$$ Solving the system of coupled first order equations...

In [2]:
t,g_o_R, p0 = var('t g_o_R p0')
g_o_R=13
p0=0.37
x_1 = function('x_1')(t)
x_2 = function('x_2')(t)
de1 = diff(x_1,t) ==  x_2
de2 = diff(x_2,t)  == -g_o_R* x_1
h=desolve_system([de1, de2], [x_1,x_2])
show(h)
Out[2]:

This (above) is the general solution.

Here (below) is that solution with initial conditions in the order [t_0, x_1(t_0), x_2(t_0)]=[0, p0, 0]

In [3]:
show(desolve_system([de1, de2], [x_1,x_2],ics=[0,p0,0],ivar=t) )
Out[3]:

GOOD we get $\phi(t)\equiv x_1(t)=\phi_0\cos(\sqrt{g/R}\,t)$ again!

======================



Solving the system of equations numerically

In [4]:
x_1,x_2,t,p0,g_o_R=var('x_1 x_2 t p0 g_o_R')

p0=0.37
g_o_R=13
P=desolve_system_rk4([x_2,-g_o_R*x_1], [x_1,x_2], ics=[0,p0,0], ivar=t, end_points=5)

# Solve a system of first order differential equations, using the Runge-Kutta 4th order algorithm
#
# Arguments:
#  [x_1'(t), x_2'(t), x_3'(t),....]: This first "tuple" consists of the right hand side of the equations for the time derivatives
#     of x_1, x_2, x_3, etc...
#  [x_1, x_2, x_3,...]: These are the functions to solve for.  (We're interested in x_1(t)=phi(t).)
#  ics: initial conditions, in the order [t0, x_1(t0), x_2(t0), x_3(t0),...]
#  ivar: name of the independent variable
#  end_points: in this case, solutions will be calculated at discrete values of the ivar, from the starting value
#     up to this ending value.
#
# Output:
#  P will consist of a set of points calculated at discrete t (time) values, in the order [t,x_1,x_2,....]
#
# The next line shows you how to extract just the [t, x_1(t)] pairs of points, and then make a "list_plot"
#   of those.
Q=[ [i,j] for i,j,k in P]
LP=list_plot(Q)

# Next we'll plot the exact solution:
MP=plot(p0*cos(sqrt(g_o_R)*t),(t,0,5),color="red")

# Now we'll show both plots together to confirm that the numerical and exact solutions match.
show(LP+MP)
Out[4]:
In [0]: