# Dynamics Example Problems¶

Selected example problems are illustrated below, including

For more information on how to use the Jupyter notebook, see Archie's Intro document.

```
# The following statements are required for the work below
from numpy import *
dtr = pi/180
g = 9.81 # m/s2
gfps = 32.2 # ft/s2
```

## Using Jupyter as a calculator¶

The problem below illustrates the use of Jupyter as a calculator.

The solution to the problem is first developed by hand on paper, using variables for all quantities, then scanned and posted with the problem. When the final solution equation is derived, it is put into code.

Here is the hand-written solution. The variables used are defined at the top (note that we don't need $W$ or $h$ for the solution). The bottom line is what we need to calculate, but it is based on a few intermediate results.

We put this solution into code as follows:

```
# symbol definitions:
e = 0.5
d = 100 # ft
vA = 75 # ft/s
phi = 60*dtr # rad
Q0 = 45*dtr # rad
# intermediate results:
vfx = vA*cos(Q0)
tf = d/vfx
vfy = vA*sin(Q0) - gfps*tf
v1 = sqrt( vfx**2 + vfy**2 )
Q1 = arctan(-vfy/vfx)
alpha = pi/2 - (phi+Q1)
v2x = e*v1*cos(alpha)
v2y = v1*sin(alpha)
# final result:
v2 = sqrt(v2x**2+v2y**2)
print('speed after bounce = {:.3f} ft/s'.format(v2))
```

speed after bounce = 31.840 ft/s

## Vectors and the cross product¶

Doing cross products is much easier with some computational help. In this case the whole problem is done in code (no hand written component).

```
rOP = array((-1, 1.5, 2)) # m
rOA = array(( 2,-1.5, 2)) # m
rOB = array(( 3, 3, 0)) # m
m = 3.0 # kg
rPA = rOA - rOP
rAB = rOB - rOA
uAB = rAB / sqrt(sum(rAB**2))
v = 6*uAB # m/s
H = cross( rPA, m*v )
print('H = ({:.2f} i {:+.2f} j {:+.2f} k) kg.m²/s'.format(*H))
```

H = (21.49 i +21.49 j +59.11 k) kg.m²/s

## Solving several simultaneous equations¶

Solving several equations simultaneouly is best done by computer.

### General theory¶

The tools of linear algebra make linear equations easy to handle. If you have not yet studied linear algebra this material might not be intelligible. But don't worry, you don't need to understand it to use it.

To solve a series of coupled linear equations such as

$$ C_{11} x + C_{12} y + C_{13} z = S_1 $$

$$ C_{21} x +C_{22} y + C_{23} z = S_2 $$

$$ C_{31} x +C_{32} y + C_{33} z = S_3 $$

they must first be written in matrix form:

$$\begin{bmatrix} C_{11} & C_{12} & C_{13} \\ C_{21} & C_{22} & C_{23} \\ C_{31} & C_{32} & C_{33} \\ \end{bmatrix} \begin{bmatrix} x \\ y \\ z \end{bmatrix}= \begin{bmatrix} S_1\\S_2\\S_3 \end{bmatrix} $$

or more compactly as:

$$ \mathbb{C} \vec{x} = \vec{s} $$

This is solved by inverting matrix $\mathbb{C}$:

$$ \mathbb{C}^{-1} \mathbb{C} \vec{x} = \mathbb{C}^{-1} \vec{s} $$

$$\vec{x} = \mathbb{C}^{-1} \vec{s} $$

### Theory Applied¶

We will now use this theory to solve the following problem that requires seven equations with seven unknowns.

First, the hand written solution. At the bottom of that development are the seven equations with seven unknowns ($N_A$, $N_B$, $\alpha$, $a_A$, $a_B$, and $\vec{a}_G$ with two components). We can solve these with a little linear algebra, as follows.

In Python we use the linalg routine to perform the matrix inversion.

```
m = 12 # kg
L = 3 # m
Q = 60*dtr # rad
w = 2 # rad/s
IG = m*L**2/12
c,s = cos(Q),sin(Q)
# NA NB alpha aA aB aGx aGy
CC = array((( 0, -1, 0, 0, 0, -m, 0 ), # Fx = 0
( 1, 0, 0, 0, 0, 0, -m ), # Fy = mg
( -L*c/2, L*s/2, IG, 0, 0, 0, 0 ), # MG = 0
( 0, 0, L*s, -1, 0, 0, 0 ), # B/A x = L w^2 cosQ
( 0, 0, -L*c, 0, 1, 0, 0 ), # B/A y = L w^2 sinQ
( 0, 0, 0, .5, 0, 1, 0 ), # G=(A+B)/2 x = 0
( 0, 0, 0, 0, .5, 0, 1 ) )) # G=(A+B)/2 y = 0
print(' check if coefficient matrix is invertable (nonzero determinant):')
print(' det(CC)={:.3f}'.format(linalg.det(CC)))
SS = array(( 0, m*g, 0, L*w**2*c, L*w**2*s, 0, 0 ))
NA,NB,alpha,aA,aB,aGx,aGy = linalg.solve(CC,SS)
print('Solution:')
print(' reactions are NA={:.2f} N, NB={:.2f} N '.format(NA,NB))
print(' angular acceleration is {:.2f} rad/s2'.format(alpha))
print('We also now know:')
print(' acceleration of ends are: aA={:.2f} m/s2, aB={:.2f} m/s2'.format(aA,aB))
print(' aG is ({:.3f} i {:+.3f} j) m/s2'.format(aGx,aGy))
```

check if coefficient matrix is invertable (nonzero determinant): det(CC)=-36.000 Solution: reactions are NA=33.29 N, NB=2.23 N angular acceleration is 2.45 rad/s2 We also now know: acceleration of ends are: aA=0.37 m/s2, aB=14.07 m/s2 aG is (-0.186 i -7.036 j) m/s2

### Anticipating Problems¶

If all of the equations are not independant, there is no solution (more here). You can easily check if this will be a problem by finding the determinant of the coefficient matrix: if it is zero (or very near zero) you will have a problem.

This is demonstrated here, using the same solution but with extra equations
derived from taking moments about other points ($\sum M_A$ and $\sum M_B$). In
this case the determinant of the coefficient matrix is pretty much zero, but
the `linalg.solve()`

routine gives an answer anyway -- a wrong answer!

```
m = 12 # kg
L = 3 # m
Q = 60*dtr # rad
w = 2 # rad/s
IA = m*L**2/3 # = IB
IG = IA/4
c,s = cos(Q),sin(Q)
zs = -m*s*L/2
zc = -m*c*L/2
# NA NB alp aA aB aGx aGy
CC = array((( 0, -1, 0, 0, 0, -m, 0 ), # Fx = 0
( 1, 0, 0, 0, 0, 0, -m ), # Fy = mg
( -L*c/2,L*s/2,IG, 0, 0, 0, 0 ), # MG = 0
( 0, L*s, IA, zs, 0, 0, 0 ), # MA = mgLcosQ/2
(-L*c, 0, IA, 0, zc, 0, 0 ), # MB = -mgLcosQ/2
( 0, 0,L*s, -1, 0, 0, 0 ), # B/A x = L w^2 cosQ
( 0, 0,-L*c, 0, 1, 0, 0 ), ))# B/A y = L w^2 sinQ
print(' check if coefficient matrix is invertable (nonzero determinant):')
det = linalg.det(CC) # find determinant of CC
print(' det(CC)={:.3e}'.format(det))
if abs(det)<1e-5:
print(' WARNING: Coefficient matrix is not invertable...!')
SS = array(( 0, m*g, 0, m*g*L*c/2, -m*g*L*c/2, L*w**2*c, L*w**2*s ))
NA,NB,alpha,aA,aB,aGx,aGy = linalg.solve(CC,SS)
print('Incorrect Solution:')
print(' reactions are NA={:.2f} N, NB={:.2f} N '.format(NA,NB))
print(' angular acceleration is {:.2f} rad/s2'.format(alpha))
```

check if coefficient matrix is invertable (nonzero determinant): det(CC)=-2.428e-12 WARNING: Coefficient matrix is not invertable...! Incorrect Solution: reactions are NA=-26.28 N, NB=-4.65 N angular acceleration is -1.52 rad/s2