Upload
ar-bangash
View
225
Download
0
Embed Size (px)
Citation preview
7/23/2019 6 Dynamics Numerical Methods
http://slidepdf.com/reader/full/6-dynamics-numerical-methods 1/23
CEE 212--Dynamics
© Keith D. Hjelmstad 2013
Numerical Methodsintegrating the equations of motion
CEE 212—Dynamics
The Mechanics Project
Arizona State University
Keith D. Hjelmstad
Contents.
1. Doing differential equations.2. Differential and integral relations
3. Trapezoidal rule.
4. Numerical integration.
5. Dynamics.
6. Projectile motion (without drag).
7. Projectile motion (with drag, explicit).
8. MATLAB code for explicit method.
9. Implicit computation (1,2).
10. Computing the gradient.
11. The gradient of the residual (1,2).
12. Reflection of the directional derivative.
13. Derivative of the length of a vector (1,2,3).
14. Derivative of a constant times vector.
15. Projectile motion (with drag, implicit).
16. MATLAB code for the Newton “while”loop.
17. Example. MATLAB code.
18. Summary.
7/23/2019 6 Dynamics Numerical Methods
http://slidepdf.com/reader/full/6-dynamics-numerical-methods 2/23
CEE 212--Dynamics
© Keith D. Hjelmstad 2013
Numerical MethodsDoing differential equations
Doing differential equations. The equations of motion
that result from Newton’s law F = ma are ordinary
differential equations (ordinary in the parlance of
differential equations means that the only derivative is
with respect to time). We face two issues in the study ofdynamics: (1) the formulation of the equations of motion
and (2) the solution of those equations. It is the second of
these that this present set of notes is about.
When we think about “solving” a differential equation
the first thing that comes to mind is finding certain
functions that, when substituted back into the original
equations satisfy it. Indeed, that is a pretty good way tothink about what it means to have solved a differential
equation (perhaps not completely or uniquely, but a
function that “works” is a very good thing).
ox
ov
)(t x
)(t v
( )t a
That perspective, however, is far too limiting to get us very far in mechanics. It is actually pretty rare to
be able to find those special functions that satisfy differential equations, especially if those equations are
nonlinear. While we will not abandon that vision of solving a differential equation (which we generally
refer to as a classical solution to the differential equation) we will augment our toolbox with an
alternative approach— numerical integration— as a means to getting solutions to problems we need to
solve in the service of doing engineering. What we will find is that we can get some very simple
algorithms to give us results that are virtually impossible to get by any other means. The price of
admission to these methods is that we must understand their limitations and we must also understand
that we need the help of the computer to do the many repetitive calculations that come up.
7/23/2019 6 Dynamics Numerical Methods
http://slidepdf.com/reader/full/6-dynamics-numerical-methods 3/23
CEE 212--Dynamics
© Keith D. Hjelmstad 2013
( )
( ) ( )
( ) ( ) ( )
t
t t
t t t
=
= =
x
v x
a v x
Numerical MethodsDifferential and integral relations
Differential and integral relations. What we know
(see the notes on Particles I: Kinematics and Kinetics).
is that velocity is the time rate of change of position
and acceleration is the time rate of change of velocity:
( ) ( ) ( )
( ) ( ) ( )
b
a
b
a
t
b at
t
b at
t t d
t t d
τ τ
τ τ
= +
= +
∫
∫
v v a
x x v
We also know that for every differential relation there
must be an associated integral relationship. For the
above equations we can also write
The integral relationships are illustrated in the figure above. In essence, the area under the acceleration
curve between any two time points is equal to the difference in velocity at those two points; the areaunder the velocity curve between any two time points is equal to the difference in position at those two
points. So if we could estimate the area under those curves then we could carry out the integration of the
equations. That is what numerical integration is all about—approximating the area under the curves.
Students of beam theory may recognize the similarity between these relationships and the relationships
between moment, shear, slope, and deflection of beams subjected to transverse loading.
x
v
a
bt
( ) ( )b at t −v v
( ) ( )b at t −x x
at
7/23/2019 6 Dynamics Numerical Methods
http://slidepdf.com/reader/full/6-dynamics-numerical-methods 4/23
CEE 212--Dynamics
© Keith D. Hjelmstad 2013
Numerical MethodsTrapezoidal Rule
Trapezoidal rule. Let us first consider the simple
problem of the integral of a scalar function of a scalar
variable. The geometric interpretation of the integral is
the area under the curve between the two limits of
integration.
Observe in the figure at left that the area under the curve
is approximately equal to the area of the trapezoid
defined by connecting the two points on the curve f (t a)
and f (t b) with a straight line. The area of the trapezoid is
[ ]12 ( ) ( ) ( )b a a b
Area t t f t f t = − +
)(t f
t at bt
( )a f t
( )b f t
( )b
a
t
t f d τ τ ∫
If the points are close enough together this area is agood representation of the actual integral so we say
[ ]( ) ( ) ( ) (1 ) ( )b
a
t
b a a bt
f d t t f t f t τ τ β β ≈ − + −∫
This approximation is called the trapezoidal rule for integration. What is does, essentially, is replace the
task of integration with the evaluation of the function at to places (which is always easy to do). This
simple observation will create a powerful method for integrating differential equations. We cangeneralize the method by introducing the parameter β (which can take values between 0 and 1) to give
the generalized trapezoidal rule
[ ]12
( ) ( ) ( ) ( )b
a
t
b a a bt
f d t t f t f t τ τ ≈ − +∫
7/23/2019 6 Dynamics Numerical Methods
http://slidepdf.com/reader/full/6-dynamics-numerical-methods 5/23
CEE 212--Dynamics
© Keith D. Hjelmstad 2013
Numerical MethodsNumerical integration
Numerical integration. Now let us take this idea
one step further. Suppose that the curve shown in red
at left is the solution to some differential equation
(with its associated integral form):
)(t f
t nt 1nt +
( )n f t
1( )n f t +
1n nt t t +∆ = −
with (known) initial condition x(0) = xo. If I take the
two points to be t a = t n and t b = t n+1 then I can write the
integral form of the equation as
( ) ( ) ( ) ( )b
a
t
b at
x f t x t x t f d τ τ = = + ∫
To solve the differential equation let us break up the region into pieces of width ∆t = t n+1 − t n and
compute the response recursively with the generalized trapezoidal rule (probably with β = 0.5) as
1
1 ( )
n
n
t
n n t x x f d τ τ
+
+
= +
∫ ( )
n n x x t =
where we use a subscript n to represent the value of x at
the time t n (and similarly for t n+1). Also let ∆t = t n+1 − t ndenote the size of the time step.
[ ]1 1 0( ) (1 ) ( ) (0) (given)n n n n o x x t f t f t x x x β β + += + ∆ + − = =
Knowing x0 = xo we can compute x1; knowing x1 we can compute x2. We can work our way forward
until we reach some place that we want to stop. All initial value problems can be approached this way.
This algorithm produces a sequence { x0 , x1 , x2 , x3 ,…, x N } which approximates the solution x(t ) that
we seek as the solution to the differential equation. The quality of the approximation depends on ∆t .
7/23/2019 6 Dynamics Numerical Methods
http://slidepdf.com/reader/full/6-dynamics-numerical-methods 6/23
CEE 212--Dynamics
© Keith D. Hjelmstad 2013
Numerical MethodsDynamics
Dynamics. Let us finally apply numerical integration to
the equations of kinematics for particle dynamics. Recall
the integral equations and initial conditions
1 1
1 1
(1 )
(1 )
n nn n
n nn n
t
t
β β
β β
+ +
+ +
= + ∆ + −
= + ∆ + −
v v a a
x x v v
where an = a(t n), vn = v(t n), and xn = x(t n), and similarly
for the values at time t n+1.
x
v
a
1nt +
1n n+ −v v
1n n+ −x x
nt t
1
1
1
1
( ) ; (0)
( ) ; (0)
n
n
n
n
t
n n ot
t
n n ot
d
d
τ τ
τ τ
+
+
+
+
= + =
= + =∫∫
v v a v v
x x v x x
Applying the generalized trapezoidal rule gives:
Again, this algorithm gives us a means for computing the sequences:
{ } { }0 1 2 0 1 2, , , ..., and , , , ..., N N x x x x v v v v
when the acceleration is known. In applications we will get the acceleration from the equation of
motion. Hence, the boxed equations will apply to all systems. The difference from one application to
another will be the equations of motion. Note that because the integration variable is time, the
equations apply directly to vectors (e.g., x and v) that are functions of time.
7/23/2019 6 Dynamics Numerical Methods
http://slidepdf.com/reader/full/6-dynamics-numerical-methods 7/23
CEE 212--Dynamics
© Keith D. Hjelmstad 2013
Numerical MethodsProjectile motion (without drag)
Projectile without drag. This algorithm
computes the entire evolution of the motion of
the pendulum subjected to gravity forces. It
has the five key steps that all of our dynamics
codes will need.
This is the simplest possible application of
numerical integration of the equations of
motion of dynamics. The equations are linear
so it is also possible to get an exact (classical)
solution to this problem. The exact solution
(which can be used to verify the code) is
The algorithm has been implemented in
MATLAB and is called projectile.m.
212
( ) o ot t g t = + −x x v n
nF mgg −=ox
ov
)(t x
1 x
3 x
n
Read given physical problem data:
for n = 0 to N − 1 Repeat the following:
,o ox v
Read given initial conditions:
Compute initial acceleration from the
equation of motion, using initial conditions:
0 g= −a n
, , ,m c g n
Set numerical analysis parameters:
, , , , ( ) /o f f ot t t N t t t β ∆ = − ∆
1
1 1
1 1
(1 )
(1 )
n
n n n n
n n n n
g
t
t
β β
β β
+
+ +
+ +
= −
= + ∆ + −
= + ∆ + −
a n
v v a a
x x v v
end (Loop over time steps)
Compute the complete state at all points
in the time history:
7/23/2019 6 Dynamics Numerical Methods
http://slidepdf.com/reader/full/6-dynamics-numerical-methods 8/23
CEE 212--Dynamics
© Keith D. Hjelmstad 2013
Numerical MethodsProjectile motion (with drag, explicit)
Explicit version with drag. This version
adds a term to the acceleration computation
to include the drag force. Ideally, we would
like to satisfy the equation of motion (which
gives the acceleration) at n + 1. But we do not
know the new velocity at the moment we
need to compute the new acceleration. So as
an approximation we use the old velocity at
that time
1 /n n ng c v m+ = − −a n v
This explicit version avoids the solution of
the nonlinear equation of motion. For small
enough time steps it generates reasonably
accurate response.
Read given physical problem data:
for n = 0 to N − 1 Repeat the following:
,o ox v
Read given initial conditions:
Compute initial acceleration from the
equation of motion, using initial conditions:
0 /o og c v m= − −a n v
, , ,m c g n
Set numerical analysis parameters:
, , , , ( ) /o f f ot t t N t t t β ∆ = − ∆
1
1 1
1 1
/
(1 )
(1 )
n n n
n n n n
n n n n
g c v m
t
t
β β
β β
+
+ +
+ +
= − −
= + ∆ + −
= + ∆ + −
a n v
v v a a
x x v v
end (Loop over time steps)
Compute the complete state at all points
in the time history:
d c v= −F v
nF mgg −=ox
ov
)(t x
1 x
3 x
n
7/23/2019 6 Dynamics Numerical Methods
http://slidepdf.com/reader/full/6-dynamics-numerical-methods 9/23
CEE 212--Dynamics
© Keith D. Hjelmstad 2013
Numerical MethodsMATLAB code for explicit method
MATLAB code. The core time-stepping loop of
the MATLAB code for the explicit method is
%... Loop over time steps
for i=1:nsteps
%..... Update time
t = t + dt;
%..... Compute new acceleration from equation of motion
speed = norm(vold);anew = -gravity*up - c*speed*vold/mass;
%..... Compute new velocity and position by trapezoidal rule
vnew = vold + dt*(beta*aold + (1-beta)*anew);
xnew = xold + dt*(beta*vold + (1-beta)*vnew);
%..... Put current state (new) into old slot to get ready for
% new step. Note that this approach allows us to only
% store two states as we carry out the calculation
aold = anew;
vold = vnew;
xold = xnew;
end % loop over time steps
Note that we will need some additional code (see projectile.m) to take care of input of physical parameter,
numerical analysis parameters, initialization, keeping track of the history, and output graphics, but this
code is the core engine of the numerical calculation. It forms the basis of all of our dynamics codes.
1 1
1 1
(1 )
(1 )
n n n n
n n n n
t
t
β β
β β
+ +
+ +
= + ∆ + −
= + ∆ + −
v v a a
x x v v
g → gravity
m → mass
t → time
dt → ∆
t β → beta
N → nsteps
Initialized before entering loop
1 /n n ng c v m+ = − −a n v
MATLAB variable
names might differ
from pseudo-code
7/23/2019 6 Dynamics Numerical Methods
http://slidepdf.com/reader/full/6-dynamics-numerical-methods 10/23
CEE 212--Dynamics
© Keith D. Hjelmstad 2013
Numerical MethodsImplicit computation
Implicit version. The nonlinear equations of motion for the
particle with drag along with the trapezoidal integration
equations are
x
v
a
1nt +
1n n+ −v v
1n n+ −x x
nt t
We want to solve these equations at each time step (as
we have done before, except that they were linear
equations before). Before we set up Newton’s method let
us do a little algebraic manipulation of those equations to
put them into a slightly different form. To do so werecognize that everything with an n subscript is known
(from the calculation at the previous time step). So let’s
rewrite the trapezoidal equations in the following form:
The two equations on the left are the trapezoidal equations and the other four equations (to the right)
are simply definitions of terms in the equations at left. The vectors cn and bn really are nothing more
than the part of vn+1 and xn+1 that can be computed from things that are known at time step n. This
form of the equations shows that both vn+1 and xn+1 are linear functions of an+1. That means it will be
easy to substitute them back into the nonlinear equation of motion. We do that next.
1 1 1 1
1 1
1 1
)(
(1 )
(1 )
n n n n
n nn n
n nn n
m mg c v
t
t
β β
β β
+ + + +
+ +
+ +
= + =
+
= + ∆ + −= + ∆ + −
0g a a n v
v v a a
x x v v
1
1
1
1
n
n
nn
nn η
γ +
+
+
+
= +
= +
a
a
x b
v c
2(1 )n n
n
n n
n n
t t
t
β β
β
+ − ∆= + ∆
= + ∆
a
a
b x v
c v
2 2(1 )
)(1
t
t
γ β
η β
− ∆=
= − ∆
where
7/23/2019 6 Dynamics Numerical Methods
http://slidepdf.com/reader/full/6-dynamics-numerical-methods 11/23
CEE 212--Dynamics
© Keith D. Hjelmstad 2013
Numerical MethodsImplicit computation
Implicit version. In the equation of motion we need the speed
and the velocity at the new time step
Since cn and η are constant with respect to finding the next new
state, we will simply think of vn+1 and vn+1 as functions of an+1 in
the following equations. Hence the residual function for
Newton’s method can be written as
1 1 1 1 1 1( ) ( ) ( )n n n n n nm m g c v+ + + + + += + +g a a n a v a
11
1 1 1
nnn
n n nv
η ++
+ + +⋅
= +
=
av c
v v
We need to do some algebra so let us suppress the subscript
n+1 from all the terms that have it while we do the algebra.
With this abbreviated notation then
( ) ( ) ( ),
( ) , ( ) ( ) ( )n
m mg c v
vη
= + +
= + = ⋅
g a a n a v a
v a c a a v a v a
We can substitute the expressions for the velocity and speed directly into the residual function g to get
( ) ( ) ( )( ) n n nm m g c η η η = + + + ⋅ + +g a a n c a c a c a
showing that what we need to do to satisfy the equation of motion is to solve the nonlinear algebraic
equation g(a) = 0 to find the new acceleration a = an+1. This task is what Newton’s method was born to
do. The only thing we need for Newton’s method is the gradient of g. Let’s compute that next.
EE D
7/23/2019 6 Dynamics Numerical Methods
http://slidepdf.com/reader/full/6-dynamics-numerical-methods 12/23
CEE 212--Dynamics
© Keith D. Hjelmstad 2013
Numerical MethodsComputing the gradient
Now augment a by adding ε h
where h = [h1, h2, h3]T . Now take the derivative with
respect to ε using the chain rule for differentiation
because
Computing the gradient. To find the new
acceleration we need to solve a nonlinearalgebraic system of equations of the form
( ) =g a 0
To do that we need to compute the gradient of
g with respect to its argument a. We can
accomplish this task with a formula called the
directional derivative
[ ]0
( ) ( ) ( )d
Dd ε
ε ε =
⋅ = + = ∇
g a h g a h g a h
Let us first show how this is the same as the
partial derivative formula for the gradient of g
that we had used in the notes Newton’s
Method . Write out the equations in long form
1 1 2 3
2 1 2 3
3 1 2 3
( , , ) 0
( , , ) 0
( , , ) 0
g a a a
g a a a
g a a a
=
=
=
where g = [g1, g2, g3]T and a = [a1, a2, a3]
T .
1 1 1 2 2 3 3
2 1 1 2 2 3 3
3 1 1 2 2 3 3
( , , )
( , , )
( , , )
g a h a h a h
g a h a h a h
g a h a h a h
ε ε ε
ε ε ε
ε ε ε
+ + +
+ + +
+ + +
1 2 31 2 3
1,2,3i i i idg g g gh h h i
d a a aε
∂ ∂ ∂= + + =
∂ ∂ ∂
( )
1,2,3i i
i
d a h
h i
ε
ε
+
= =∂
Putting this result into matrix form we have
1 1 11
1 2 31
2 2 2 22
1 2 33
3 3 3 3
1 2 3
g g gdg
a a ad h
dg g g gh
d a a a hdg g g g
d a a a
ε
ε
ε
∂ ∂ ∂ ∂ ∂ ∂ ∂ ∂ ∂
=
∂ ∂ ∂ ∂ ∂ ∂
∂ ∂ ∂
[ ]0
( ) ( )d
d ε
ε ε =
+ = ∇
g a h g a h
So
CEE 1 D
7/23/2019 6 Dynamics Numerical Methods
http://slidepdf.com/reader/full/6-dynamics-numerical-methods 13/23
CEE 212--Dynamics
© Keith D. Hjelmstad 2013
The second term does not involve a, therefore the
derivative is zero (the derivative of a constant is
zero): D(mgn) = 0.
The third term is a product of functions that arefunctions of a. Therefore, we need the chain rule
and product rule for differentiation. Those work the
same for the directional derivative as for the
ordinary derivative.
Numerical MethodsThe gradient of the residual
The gradient of the residual. Recall the
residual function of the equation of motionis defined as
( )0n
d D
d ε η ε η
ε = = + + = v c a h h
( )2
2
2 2
D v D D
v Dv
v Dv
Dvv
η η
η
η
= ⋅ + ⋅
= ⋅ + ⋅
= ⋅
⋅=
v v v v
h v v h
v h
v h
The function has three terms added together.
The derivative of the sum is the sum of the
derivatives. So let us compute them each
individually. The first term is:
Now let us compute the directional derivative of the
speed v(a). A simple way to do this computation is to
realize that the square of the speed is the dot product
of the velocity with itself:2
v = ⋅v v
To get set up let us first compute the directional
derivatives of the velocity ( ) n η = + av a c
( ) ( ) ( )m mg c v= + +g a a n a v a
( )0
( ) d
D Dd ε
ε ε =
= ⋅ = + g g a h g a h
We need to compute the gradient of this
function. We will do it with the directional
derivative. For short let us use Dg to
represent the directional derivative of g
( ) ( )0
d D m m m
d ε ε
ε = = + = a a h h
In other words, the directional derivative of
ma in the direction h is mh.
CEE 212 D
7/23/2019 6 Dynamics Numerical Methods
http://slidepdf.com/reader/full/6-dynamics-numerical-methods 14/23
CEE 212--Dynamics
© Keith D. Hjelmstad 2013
Numerical MethodsThe gradient of the residual
The gradient of the residual (cont’d).
Putting the pieces together for the thirdterm we get
where m = v/v is the unit vector pointing inthe direction of the velocity and I is the
identity matrix. Note that the transpose of a
column matrix (vector) is a row vector so
Using the relationships we have computed
previously we get
[ ] ( ) T m cv cvη η = ∇ = + +A g I m m
Now we can finish computing the gradient of the
residual:
[ ]
( )
T
T
T
D m cv
m cv
m cv cv
η
η
η η
= + +
= + +
= + +
g h m m I h
I h m m I h
I m m h
We can identify the gradient of the residual. It is
given in the box below.
This is the gradient matrix that we need for
implementing Newton’s method to solve our nonlinear
system of equations. There is a fair amount of work to
get it, but it is essential for the algorithm.
( )
( ) ( ) ( )
D D m mg c v
D m D mg D cv
= + +
= + +
g a n v
a n v
( ) ( ) ( )
( )
( )
( )T
T
D cv c Dv cv D
c cvv
cv cvv v
cv
cv
cv
η η
η
η
η
η
η
= +
⋅ = +
⋅
= +
= ⋅ +
= +
= +
v v v
v hv h
v h v
h
m h m h
mm h h
mm I h
( ) ( ) ( )T T ⋅ = ⋅ = = m h m m m h m m h mm h
CEE 212 D i
7/23/2019 6 Dynamics Numerical Methods
http://slidepdf.com/reader/full/6-dynamics-numerical-methods 15/23
CEE 212--Dynamics
© Keith D. Hjelmstad 2013
The directional derivative is computed asNumerical MethodsReflection on the directional derivative
Reflection on the directional derivative.
The gradient of a vector valued function ofa vector variable is simply the matrix of
partial derivatives of the function with
respect to the arguments
is just a very happy result of calculus. This
relationship gives us the route to computing the
gradient through the directional derivative (and note
that we never need to assign a value to the arbitrary
vector h).
The beauty of the directional derivative approach is
that it allows a very simple way to deal with functions
whose arguments are vectors (which is very often the
case in mechanics).
which, if you get right down to it, is simply an
ordinary scalar derivative with respect to ε . For the
purposes of that derivative all of the other terms are
treated as constants (so it does not matter so much if
they are vectors or scalars—just carry them along!).
The fact that
( )0
( ) d
D Dd ε
ε ε =
= ⋅ = + g g a h g a h
In order to use this form of the computation
we have to write out in long form how each
of the functions gi depends upon all of the
independent variables ai. That is generally possible but often a huge mess of algebra.
What the directional derivative does for us
is give us a different way of organizing the
calculation.
1 1
1
1
( )
n
n n
n
g g
a a
g g
a a
∂ ∂ ∂ ∂
∇ = ∂ ∂
∂ ∂
g a
( ) [ ]0
d d ε
ε ε =
+ = ∇ g a h g h
CEE 212 D i
7/23/2019 6 Dynamics Numerical Methods
http://slidepdf.com/reader/full/6-dynamics-numerical-methods 16/23
CEE 212--Dynamics
© Keith D. Hjelmstad 2013
Numerical MethodsExample: derivative of the length of a vector
[ ]
( )
( ) ( )
( ) ( )
( ) ( )
( ) ( )
12
12
12
12
12
0
0
0
12
0
1
20
12
12
( ) ( )
( ) ( )
( ) ( )
( ) ( ) ( ) ( )
( ) ( ) ( ) ( )
2
d Dg g
d
d
d
d
d
d
d
ε
ε
ε
ε
ε
ε ε
ε ε ε
ε ε ε
ε ε ε ε ε
ε ε ε ε
=
=
=
−
=
−
=
−
−
⋅ = +
= + ⋅ +
= + ⋅ +
= + ⋅ + + ⋅ +
= + ⋅ + ⋅ + + + ⋅
= ⋅ ⋅ + ⋅
= ⋅ ⋅
⋅=
⋅
v h v h
v h v h
v h v h
v h v h v h v h
v h v h h v h v h h
v v h v v h
v v v h
v h
v v
chain rule
product rule
The computation of the directional derivative
of the length of a vector goes as follows
( )g = ⋅v v v
The length of a vector v
is the square root of the
vector dotted with itself
( ) Dg ⋅
⋅ =⋅
v hv h
v v
Note that there are three basic
tasks: (1) augmenting v by ε h,
(2) taking ordinary derivative
with respect to ε , (which here
involves chain rule and productrule) and (3) evaluating at ε =0.
The final result is
CEE 212 D i
7/23/2019 6 Dynamics Numerical Methods
http://slidepdf.com/reader/full/6-dynamics-numerical-methods 17/23
CEE 212--Dynamics
© Keith D. Hjelmstad 2013
Numerical MethodsDerivative of the length of a vector
T
v v
⋅ =
v vh h
[ ] [ ]T
•
= • • • • = • = ⋅ •
a b a b
[ ]( ) Dg g⋅ = ∇v h h
It is often useful to note how the dot product
notation and the matrix “transpose” notation can be interchanged. We think of a vector as being
represented by a 3 by 1 column matrix. Hence the
transpose of a vector would be a 1 by 3 row
matrix. So the dot product also looks like this
( ) Dg ⋅
⋅ = ⋅
v hv h
v v
Recall that, by the rules of matrix multiplication, a
1 by 3 multiplying a 3 by 1 gives a 1 by 1 matrix
(scalar). The dot product of vectors is a scalar. We
can also note that
Our example. Remember that we are really
trying to compute the gradient of g for use in
Newton’s method. What we got was
[ ]T • • • • = • • • • = • • •
• • • •
a b
This is called the outer product of vectors. The
order of operations is important for vectors.
What we need to have is an expression in a
form that we can factor out the gradient of g
because
[ ]T
gv
∇ =
v
Noting the matrix multiply equivalents wecan write
Therefore the gradient matrix for the length
of a vector can be written as
In other words, it is a row matrix whose
contents are the vector components
normalized by the length of the vector
CEE 212 D ami s
7/23/2019 6 Dynamics Numerical Methods
http://slidepdf.com/reader/full/6-dynamics-numerical-methods 18/23
CEE 212--Dynamics
© Keith D. Hjelmstad 2013
Numerical MethodsDerivative of the length of a vector
( )12
2 2 2
1 2 2
2 2 21 2 2 1 2 3
( )
( , , )
g
v v v
v v v g v v v
= ⋅
= + +
= + + =
v v v
1 2 3
, ,g g g
gv v v
∂ ∂ ∂∇ =
∂ ∂ ∂
( ) ( )
( )( ) ( )
( )
( ) ( )( )
12
12
12
12
12
12
2 2 2 1 111 2 2 12
2 2 21
1 2 2
2 2 2 2 211 2 2 22
2 2 22
1 2 2
2 2 2 3 311 2 2 32
2 2 23
1 2 2
2
2
2
v vgv v v v
v vv v v
v vgv v v v
v vv v v
v vgv v v v
v vv v v
−
−
−
∂= + + = =
∂ + +
∂= + + = =
∂ + +
∂= + + = =
∂ + +2 2 2
1 2 2v v v v= + +
If you are wondering how the computation of
the gradient matrix for the length of a vector looks if we just put it into component form we
can do that. The function can be written out as
We can compute the partial derivatives of g with
respect to each of the arguments as
The gradient matrix is defined as the matrix
of partial derivatives (a row matrix)
1 2 3
31 2
, ,
, ,T
g g gg
v v v
vv v
v v v v
∂ ∂ ∂∇ =
∂ ∂ ∂
= =
v
Putting in the partial derivative expressions
we just computed we get
which is exactly the same as the result we got
using the directional derivative. The choice
of which method to use depends upon the
specific function g. It is not always
immediately obvious at the start which onewill yield the cleaner derivation.
CEE 212 Dynamics
7/23/2019 6 Dynamics Numerical Methods
http://slidepdf.com/reader/full/6-dynamics-numerical-methods 19/23
CEE 212--Dynamics
© Keith D. Hjelmstad 2013
Numerical MethodsExample: derivative of a constant times a vector
[ ]
[ ]
0
0
( ) ( )d
D cd
d c
d
c
ε
ε
ε ε
ε ε
=
=
⋅ = +
= +
=
g v h v h
v h
h
[ ]c c=h I h
[ ] [ ]c∇ =g h I h
Let’s take a look at what happens when we
compute the directional derivative of thefunction
( ) c=g v v
where c is a constant scalar. We want to take the
derivative of g with respect to v. The derivation
goes as follows
That is a pretty simple result, but remember thatwe are looking for the gradient of g to use in
Newton’s method
[ ]( ) Dg ⋅ = ∇v h g h
The gradient should be a 3 by 3 matrix.
multiplying the arbitrary vector h. It looks
like what we got was only the scalar c
multiplying h. We can fix this situation by
noting that any vector that multiplies theidentity matrix is the same vector. Hence,
we can write
Now we can write the directional derivative
in a form that allows us to identify the
gradient matrix
[ ] [ ]
0 0
0 00 0
c
g c cc
∇ = =
I
Hence,
Note that in MATLAB the 3 by 3 identitycan be create as I = eye(3) .
CEE 212--Dynamics
7/23/2019 6 Dynamics Numerical Methods
http://slidepdf.com/reader/full/6-dynamics-numerical-methods 20/23
CEE 212--Dynamics
© Keith D. Hjelmstad 2013
Numerical MethodsProjectile motion (with drag, implicit)
Set parameters:
, , ,
( ) /
(1 )
itmax 10
tol 1. 8
o f
f o
t t t
N nsteps t t t
t
e
β
η β
∆
= = − ∆
= − ∆=
= −
Algorithm. For the implicit calculation we
need to implement Newton’s method. Thatrequires a few additional parameters
Initialize to prepare for Newton loop
( )
1
1
11 1
1
; /
n n
n
T
n n
its its
v v
m m g c v
m cv cv
err
η
η η
+
+
−+ +
= +
= +
= ⋅ =
= + +
= + +
= −
= ⋅
v c a
v v m v
g a n v
A I mm
a a A g
g g
end (Newton “while” loop)
At the current time step compute the state:
1
1; 0;
n n n
n n
err its
t β
+
= =
= + ∆
=
c v a
a a
while (err > tol) and (its < itmax)
Update position and velocity
1 1
1 1
(1 )
(1 )
n n n n
n n n n
t
t
β β
β β
+ +
+ +
= + ∆ + −
= + ∆ + −
v v a a
x x v v
Newton “while” loop
The time-stepping setup is exactly the same
as the explicit calculation. The computation
of the state is a bit more complex. Theexplicit method estimated an+1 as
1 /n n ng c v m+ = − −a n v
This single line gets replaced by the
Newton “while” loop at right.
CEE 212--Dynamics
7/23/2019 6 Dynamics Numerical Methods
http://slidepdf.com/reader/full/6-dynamics-numerical-methods 21/23
CEE 212--Dynamics
© Keith D. Hjelmstad 2013
%... Set initial values for Newton loop
err = 1; its = 0;
cn = vold + beta*dt*aold;
anew = aold;
%... Newton iteration to compute the acceleration anew
while (err > tol) && (its < itmax)
its = its + 1;
vnew = cn + eta*anew;
speed = norm(vnew);
coeff = c*speed*eta;
g = mass*(anew + gravity*up) + c*speed*vnew;
m = vnew/speed;
A = (mass + coeff)*eye(3) + coeff*m*m';
anew = anew - A\g;err = norm(g);
end % while
vnew = vold + dt*(beta*aold + (1-beta)*anew);
xnew = xold + dt*(beta*vold + (1-beta)*vnew);
Numerical MethodsMALAB code for the Newton “while” Loop Variables defined earlier in
the code include:
Previous state:xol d, vol d, aol d
Numerical integration
parametersbet a, et a, dt
Newton iteration parameters
t ol , i t max
Physical constantsc, gr avi t y, mass, up
Arrays:
3 by 1 matricesxol d, vol d, aol d, cnxnew, vnew, anew, g
3 by 3 matrix:A
MATLAB Coding. To help to fix the ideas relative to how those
algorithms fit in the context of a MATLAB code the following
segment has been “clipped” from the projectile motion code that
treats drag with the implicit approach.
CEE 212--Dynamics
7/23/2019 6 Dynamics Numerical Methods
http://slidepdf.com/reader/full/6-dynamics-numerical-methods 22/23
CEE 212 Dynamics
© Keith D. Hjelmstad 2013
Numerical MethodsExample (MATLAB code)
The algorithm gives the following result for
the given conditions. Note the effect of thefluid resistance (red) on the projectile. The
result w/o fluid (blue) is computed by
integrating the equations of motion directly.
*-------------------------------------------*
| PROJECTILE MOTION PROGRAM |
| (Implicit Version) |
| K. D. Hjelmstad |
| |
| Original Version: 07.29.2012 |
| Latest Update: 09.01.2013 |
*-------------------------------------------*
PHYSICAL PROPERTIES
Acceleration of gravity 9.8100
Drag coefficient (rho.Cd.Ap/2) 0.0020
Mass 2.0000
INTEGRATION OF EQUATIONS
Initial time (to) 0.000Final time (tf) 12.000
Time increment (dt) 0.020
Numerical integration (beta) 0.500
Number of time steps 600
Number of steps to report 600
Newton iteration tolerance 1.00e-07
Maximum Newton iterations 10
INITIAL CONDITIONS
Initial position (x) 0.000
Initial position (y) 0.000
Initial position (z) 55.000
Initial velocity (x) 25.000
Initial velocity (y) 15.000
Initial velocity (z) 50.0000 50 100 150 200 250 300
0
20
40
60
80
100
120
140
160
180
200
x
z
Trajectory z vs. x
CEE 212--Dynamics
7/23/2019 6 Dynamics Numerical Methods
http://slidepdf.com/reader/full/6-dynamics-numerical-methods 23/23
CEE 212 Dynamics
© K h D H l d 0 3
Numerical Methods
SummarySummary. The classical solution of differential equations is
great for linear systems and is often difficult if not impossible
for nonlinear differential equations. The equations of dynamics
are, most of the time, nonlinear.
In this set of notes we introduce the idea of numerical
integration of the equations of motion using a technique called
the generalized trapezoidal rule to take care of the derivative
relationships between position, velocity, and acceleration.
We observe that when we use the trapezoidal rule in
conjunction with the equation of motion, the set of equations
boils down to a nonlinear algebraic equation that needs to be
solved at each time step. We can use Newton’s Method (see the
previous set of notes) to take care of this task.
When we set up the algorithm we need to solve the problem is
involves a loop over time steps and inside of that loop a Newton
“while” loop to converge on the solution to the nonlinear
algebraic equation for that particular time step.
ox
ov
)(t x
)(t v
( )t a
One of the first things that we realize when we take this approach is that numerical methods exchangecalculus computations for algebra computations. The cost of making that favorable switch is that there
are lots and lots of computations. For this reason, we always use the computer to carry out these
computations. The framework set up in these notes will hold for all of the Computing Projects in this
course. The only thing that will change is the equation of motion.