Physics 281 - Computational Physics

Wednesday/Friday Section

Fall 2009

Exercise 11 - Using MATLAB to solve a Second Order ODE

Practice

Try adding a calculation of the energy to the example "falling ball" script described in lecture. (The link to the example program is here) Make a graph of the energy versus time to see whether it is conserved in our numerical solution.

Calculation

Write a script to solve the equation of motion of a pendulum using the Euler Method. The equation is:

where g is the gravitational acceleration, l is the length of the pendulum, and theta is the angle of the pendulum from vertical.

The exact solution for the case where the pendulum is released at some initial angle theta0 at t=0 (and for small values of the angle theta) is:

We will write a MATLAB script to solve this problem using the iterative method described in class and display the results. The first step is to rewrite the second order equation as two first order DEQ's:

Compute the motion of a 4m pendulum with initial conditions omega=0 and theta = 0.01 (a small angle!!) for t from 0 to 12 seconds. (g is 9.8 m/s/s) Use a time step that is small enough to give good agreement with the analytical solution. Plot your numerical solution along with the analytical solution for comparison and submit your script and plot.

Extra Credit

Compute the energy of the pendulum for each time step in your solution and plot the result. (assume mass is one kg.) Is the energy conserved? Do you expect it to be?

Go to Ph281 Home

Go to Ph281 Topics