Difference between revisions of "Matlab Primer"

From Sean_Carver
Jump to: navigation, search
(Pendulum on a movable support)
(Pendulum on a movable support)
Line 6: Line 6:
 
Consider a pendulum of mass ''m'' and length ''ℓ'', which is attached to a support with mass ''M'' which can move along a line in the ''x''-direction. Let ''x'' be the coordinate along the line of the support, and let us denote the position of the pendulum by the angle ''θ'' from the vertical.  
 
Consider a pendulum of mass ''m'' and length ''ℓ'', which is attached to a support with mass ''M'' which can move along a line in the ''x''-direction. Let ''x'' be the coordinate along the line of the support, and let us denote the position of the pendulum by the angle ''θ'' from the vertical.  
  
[[File:pendulumWithMovableSupport.png|thumb|right|300px|Sketch of the situation with definition of the coordinates (click to enlarge)]]
+
[[Image:pendulumWithMovableSupport.png|thumb|right|300px|Sketch of the situation with definition of the coordinates (click to enlarge)]]
  
 
The kinetic energy can then be shown to be
 
The kinetic energy can then be shown to be

Revision as of 21:21, 2 November 2012

Today's lecture will be on MATLAB and PENDULA (plural of PENDULUM). Your next lab assignment motivated the topic.

My name is Sean Carver; I am a research scientist in Mechanical Engineering. I have been programming in MATLAB for almost 20 years and programming computers for almost 30 years.

Pendulum on a movable support

Consider a pendulum of mass m and length , which is attached to a support with mass M which can move along a line in the x-direction. Let x be the coordinate along the line of the support, and let us denote the position of the pendulum by the angle θ from the vertical.

Sketch of the situation with definition of the coordinates (click to enlarge)

The kinetic energy can then be shown to be


\begin{align}
T &= \frac{1}{2} M \dot{x}^2 + \frac{1}{2} m \left( \dot{x}_\mathrm{pend}^2 + \dot{y}_\mathrm{pend}^2 \right) \\
&= \frac{1}{2} M \dot{x}^2 + \frac{1}{2} m \left[ \left( \dot x + \ell \dot\theta \cos \theta \right)^2 + \left( \ell \dot\theta \sin \theta \right)^2 \right], 
\end{align}

and the potential energy of the system is

 V = m g y_\mathrm{pend} = - m g \ell \cos \theta .

The Lagrangian is therefore


\begin{align}
L &= T - V \\ 
&= \frac{1}{2} M \dot{x}^2 + \frac{1}{2} m \left[ \left( \dot x + \ell \dot\theta \cos \theta \right)^2 + \left( \ell \dot\theta \sin \theta \right)^2 \right] + m g \ell \cos \theta \\
&= \frac{1}{2} \left(  M + m \right) \dot x^2 + m \dot x \ell \dot \theta \cos \theta + \frac{1}{2} m \ell^2 \dot \theta ^2 + m g \ell \cos \theta 
\end{align}

Now carrying out the differentiations gives for the support coordinate x

\frac{\mathrm{d}}{\mathrm{d}t} \left[ (M + m) \dot x + m \ell \dot\theta \cos\theta \right] = 0,

therefore:

  (M + m) \ddot x + m \ell \ddot\theta\cos\theta-m \ell \dot\theta ^2 \sin\theta = 0

indicating the presence of a constant of motion. Performing the same procedure for the variable \theta yields:

\frac{\mathrm{d}}{\mathrm{d}t}\left[ m( \dot x \ell \cos\theta + \ell^2 \dot\theta ) \right] + m \ell (\dot x \dot \theta + g) \sin\theta = 0;

therefore

\ddot\theta + \frac{\ddot x}{\ell} \cos\theta + \frac{g}{\ell} \sin\theta = 0.\,

These equations may look quite complicated, but finding them with Newton's laws would have required carefully identifying all forces, which would have been much harder and more prone to errors. By considering limit cases, the correctness of this system can be verified: For example, \ddot x \to 0 should give the equations of motion for a pendulum which is at rest in some inertial frame, while \ddot\theta \to 0 should give the equations for a pendulum in a constantly accelerating system, etc. Furthermore, it is trivial to obtain the results numerically, given suitable starting conditions and a chosen time step, by stepping through the results iteratively.