Docsity

Numerical Analysis - Programming Assignment III | MATH 128A, Assignments of Mathematical Methods for Numerical Analysis and Optimization

Toggle sidebar
bg1
UCB Math 128A, Spring 2009: Programming Assignment 3
Due April 15
In this assignment, we will study the evolution of a double pendulum. The state of the config-
uration at any time tis given by the angles θ1(t) and θ2(t), see figure below.
θ1
θ2
The MATLAB utility pendplot.m on the course webpage can be used to visualize the double
pendulum in any configuration. Here is an example of how to use it, to animate the motion
θ1(t) = 2 sin t,θ2(t) = sin(2t):
for t=0:0.01:10, pendplot(2*sin(t),sin(2*t)); end
This motion was of course just made up and does not correspond to a true, physical motion. Now
we will solve for the actual evolution of the pendulum for various initial conditions!
1. Assuming that the lengths of the bars are 1, the masses at the end of the bars are 1, and that
the constant of gravity is 1, the equations of motion for the double pendulum can be written:
θ00
1=−3 sin θ1−sin(θ1−2θ2)−2 sin(θ1−θ2)·(θ02
2+θ02
1cos(θ1−θ2))
3−cos(2θ1−2θ2)(1)
θ00
2=2 sin(θ1−θ2)(2θ02
1+ 2 cos θ1+θ02
2cos(θ1−θ2))
3−cos(2θ1−2θ2)(2)
Rewrite (1),(2) into a system of 1st order equations by introducing the angular velocities
ω1=θ0
1and ω2=θ0
2. The current state of the pendulum can then be described by the vector
y= (θ1, θ2, ω1, ω2), and the 1st order system can be written as ˙
y=f(y). Write a MATLAB
function fpend.m of the form
function ydot = fpend(y)
which evaluates f(y).
Your report should contain the 1st order system of equations and your MATLAB function
fpend.m.
Turn page −→
pf2
Discount

On special offer

Partial preview of the text

Download Numerical Analysis - Programming Assignment III | MATH 128A and more Assignments Mathematical Methods for Numerical Analysis and Optimization in PDF only on Docsity!

UCB Math 128A, Spring 2009: Programming Assignment 3

Due April 15

In this assignment, we will study the evolution of a double pendulum. The state of the config- uration at any time t is given by the angles θ 1 (t) and θ 2 (t), see figure below.

θ 1

θ 2

The MATLAB utility pendplot.m on the course webpage can be used to visualize the double pendulum in any configuration. Here is an example of how to use it, to animate the motion θ 1 (t) = 2 sin t, θ 2 (t) = sin(2t):

for t=0:0.01:10, pendplot(2sin(t),sin(2t)); end

This motion was of course just made up and does not correspond to a true, physical motion. Now we will solve for the actual evolution of the pendulum for various initial conditions!

  1. Assuming that the lengths of the bars are 1, the masses at the end of the bars are 1, and that the constant of gravity is 1, the equations of motion for the double pendulum can be written:

θ′′ 1 =

−3 sin θ 1 − sin(θ 1 − 2 θ 2 ) − 2 sin(θ 1 − θ 2 ) · (θ′ 22 + θ′ 12 cos(θ 1 − θ 2 )) 3 − cos(2θ 1 − 2 θ 2 )

θ′′ 2 = 2 sin(θ 1 − θ 2 )(2θ′ 12 + 2 cos θ 1 + θ′ 22 cos(θ 1 − θ 2 )) 3 − cos(2θ 1 − 2 θ 2 )

Rewrite (1),(2) into a system of 1st order equations by introducing the angular velocities ω 1 = θ 1 ′ and ω 2 = θ′ 2. The current state of the pendulum can then be described by the vector y = (θ 1 , θ 2 , ω 1 , ω 2 ), and the 1st order system can be written as ˙y = f (y). Write a MATLAB function fpend.m of the form

function ydot = fpend(y)

which evaluates f (y). Your report should contain the 1st order system of equations and your MATLAB function fpend.m.

Turn page −→

  1. Implement a fourth-order Runge-Kutta method that integrates the system y˙ = f (y) from t = 0 to t = 100 with stepsize h = 0.05. Use the four initial conditions described in the table below. You can put the command pendplot(y(1),y(2)); at the end of each step to visualize the motion of the pendulum, which might be fun and might help you debug your code. You do not need to include these plots in your report.

Case θ 1 (0) θ 2 (0) ω 1 (0) ω 2 (0) 1 1 1 0 0 2 π 0 0 10 −^10 3 2 2 0 0 4 2 2 + 10−^3 0

For each case, plot the function θ 2 (t) versus time. Cases 3 and 4 demonstrate the initial value sensitivity of the system, namely, that a small perturbation can lead to drastically different solutions. Your report should contain the MATLAB commands required to produce the results, and the four plots of θ 2 (t).

  1. Run Case 1 in problem 2 with the five stepsizes h = 0. 05 / 2 (k−1), k = 1, 2 , 3 , 4, and h = 0.001. Compute the value of θ 2 (t = 100) for each stepsize. Consider the last result the exact solution, and plot the four errors as a function of h in a loglog-plot. Estimate the order of convergence from the slope. Your report should contain the MATLAB commands used, the five values of θ 2 (t = 100), the loglog-plot, and the estimated slope.