Lecture 8 - Numerical Techniques

advertisement
Professor Walter W. Olson
Department of Mechanical, Industrial and Manufacturing Engineering
University of Toledo
Solving ODE
Outline of Today’s Lecture
 Review
 SIMULINK
 Two common mathematical problems is controls
 Numerical Methods
 Newton Raphson
 Homogeneous Solution
 Euler Method
 Runge Kutta
Simulink
SIMULINK
SIMULINK
SIMULINK
Two Mathematical Problems
Frequently Encountered in Controls
 Find the roots of an equation
 Methods
 Trial and Error (bracketing methods add a bit of science to this)
 Graphics
 Closed form solutions (e.g.: quadratic formula)
 Newton Raphson
 Find the solution at a given time for given conditions
 Various differential and difference equations analytic solutions (sometimes
reformulated as find the roots problem)
 Numerical Methods




Newton Cotes Methods (trapezoidal rule, Simpson’s rule. etc. for integration)
Euler’s Method
Runga Kutta/Butcher Methods
Many other techniques (Adams-Bashforth, Adams-Milne, Hermite–Obreschkoff,
Fehlberg, Conjugate Gradient Methods, etc.)
Numerical Methods
 Solutions can be approximated using numerical methods
 Why Numerical Methods?
 Analytical methods may not exist to solve for the exact roots or
the exact solution
 Use of computers
 Flexibility of making changes
Numerical Methods
 Numerical methods follow the procedure
 Step1: Initialize: Select some initial value
 Step2: Estimate using (guess, some analytical technique) a new
value at increment “i”
 Step 3: Is the system converging? If not, use something else. We
usually know a priori whether a method will converge or not
form mathematics. Therefore, this step is often omitted.
 Step 4: Is the change from the previous value to current value
smaller than our acceptable error?
 If not, make the current value the previous value and return to step 2.
 If so, stop and accept the new value as the solution.
Newton Raphson Method for
finding roots
f(t)
 Probably the most common
numerical technique
 simple
 efficient
 flexible
f(ti)
 It can be shown from a truncated
Taylor’s Series that
df (ti )
 (ti 1  ti )
dt
new value = old value + slope * step
f (ti 1 )  f (ti ) 
therefore, solving for ti 1
ti 1  ti 
f (ti )
df (ti ) / dt
 Provided that the slope at the test
points is consistent, we can iterate
to a solution within our error
tolerance
ti+1
ti
t
Problems occur if the slope reverses
sign such as in an oscillation or
becomes very flat
F ( s )  5s 4  8s 3  15s  20 s  22
-1 seems to be a good first guess
F ( 1)  1  2  5  10  22  48 =32
F ( 1)  5  8  15  20 s  22  14
F ( si )
32
si 1  si 
 1 
 3.2857
F ( si )
14
2
Example
 Find the roots of
F ( s)  s5  2s4  5s3  10s2  22s  48
To within 0.01 of the value of s
the root lies between -1 and -3.2857
   3.2857    1  2.2857
F ( 3.2857)  243.53
F ( 3.2857)  417.2
si 1  2.702
   2.702    -3.2857   0.5837
F ( 2.702)  74.487
F ( 2.702)  186.17
si 1  2.302   0.4
F ( 2.302)  19.126
F ( 2.302)  98.266
si 1  2.107   0.195
 There appears to be a crossing
between -2 and 0, but where?
F ( 2.302)  2.838
F ( 2.302)  70.164
si 1  2.067   0.04
F ( 2.067)  0.00219
F ( 2.067)  65.137
si 1  2.065
  0.002  0.01 Stop!
ODE for Linear Control Theory
 In Linear Control Theory, the equations that are encountered are almost always
of the form
dx n
dx n 1
dx n  2
dx
a0 n  a1 n 1  a2 n  2   an 1
 an x ( t )  u ( t )
d t
d t
d t
dt
with constant coefficients subject to initial conditions.
Most problems are 2nd order.
The electric motor example:
dia
Ra ia Kb dq Va



dt
La La dt La
d 2q Kia b dq


dt
J J dt
Subject to {Va(0), ia(0)=0 and q(0) = 0}
Solution Methods
 To solve
dx n
dx n 1
dx n  2
a0 n  a1 n 1  a2 n  2 
d t
d t
d t
 an 1
We can use







Reduction in order
Undetermined coefficients
Variation of parameters
Laplace Transforms
Superposition of particular integrals
Cauchy-Euler equation
Numerical methods
dx
 an x ( t )  u ( t )
dt
Reduction of Order
 The object is to reduce the order of
the equation by substitutions until
it can be solved
 Example:
A hanging cable with a weight of w per
unit length under tension T:
T
y
H  T cos q
tan q 
W  T sin q  ws
dy W

dx H
d 2 y 1 dW w ds w
 dy 



1

 
dx 2 H dx H dx H
 dx 
dy
dp w
Let p  , then

1  p2
dx
dx H
dp
wdx

H
1  p2
wx
dy
wx
 p
 sinh
H
dx
H
wx 

dy   sinh
 dx
H 

with limits x=0, y=0 and x=x, y =y
sinh 1 p 
q
H
s
x
y
W
w
 wx  
cos
h
 H   1 , a catenary
H 

2
Homogenous Case
2) Repeated Real Roots: Assume roots
d t
d t
dt
r and r+1 are repeated, that is,
a0 n  a1 n 1  a2 n  2   an 1
 an x ( t )  0
dx n
dx n 1
dx n 2
dx
Then the term in the solution
we form the characteristic equation
corresponding to the repeated root
and solve for its roots
is mr  mr 1 and if there were v
repeated roots of the same value,
a0mn  a1mn1  a2mn2   an 1m  an  0
(k0  k1 x)em t
the
term
would
be
We have three possible outcomes for
When
d t
r
(k0  k1 x  k2 x2 ...  kvr xvr )emrt
the roots that we must consider:
1) Real Distinct Roots : for p distinct
real roots, the solution term is of
the form
c1e
p
mp t
 c2 e
 c2 e
m p 2 t

 c p emt
Therefore the complete solution accounting for all possible roots is
y   ci e
i 1
m p1t
3) Complex Conjugate Roots: Assume
that roots, ms  (a  bi) and ms1  (a  bi)
The corresponding term of the
solution is eat l1 sin bt  l2 cos bt 
m p i 1t
r
   (k0  k1 x  k2 x ...  kv x )e
j
 j 1 
2
where p  r  s  n, the total number of roots
vj
m jt
s


   e ah t lh sin bh t  lh cos bh t 
1
2

 h 1 
Homogenous Example
A weight of 15 Kgf is supported (x = 0, at rest,) by a spring with a spring rate of
50 N/m. At t = 0, the weight is extended by 20 centimeters and released.
Model and solve.
mx  bx  kx  0
15 y 2  17 y  50  0
17  172  4 *15*50
y1,2 
2 *15
y1  0.5667  1.7356i
y2  0.5667  1.7356i
x (t )  e 0.5667 t c1 sin 1.7356t   c2 cos 1.7356t 
mx  kx  0
x(0)  0.2
x (t )  0
x (0)  0.2  c2 cos 1.7356t   c2  0.2
x (0)  0  c1  0.0653
x (t )  e 0.5667 t 0.0653sin(1.7356t )  0.2cos 1.7356t 
Euler Method
 Our goal is to solve equations of the
form
dy
 f ( x, y )
dx
Prediction
yi
yi+1
}
 The theory for the Euler method is
the same as that of the Newton
Raphson Method:
dy
*h
dx
new value = old value + slope*step
yi 1  yi 
crossing, we predict where the next
value of the curve will be and then
 Make successive estimates of yi+1
xi+1
}
 Rather than now solve for an axis
xi
step h
Error
Example
mx  bx  kx  0
15 x  17 x  50 x  0
assume x = 0.2, x  0 at t=0
try a time step h = 0.1
continuing :
 0
 x
 0.1999  
 x    0.0013    50
 i 3 

 15
...
dx
dx
17
50
 x,
 x x
dt
dt
15
15
1 
 0
 x
d  x 
 50
17     f ( x, t )


dt  x   
   x
15 
 15
 x
 x
d  x


 x
 x
 x  h
dt
  i 1   i  0
 i 0
1 
 0
 x
0.2  
 0.2   0.1   0.2 


50
17
 x
 
 0.0007 
   0 
  i 1  0   


15 
 15
1 
 0
 x
 0.2  
  0.2   0.1   0.1999 


50
17
 x


 0.0013
   0.0007 
  i  2  0.0007   


15 
 15
1 
 0.1999 
 0.1999 


0.1

17
 0.002 
   0.0013


15 
Example
 Try a smaller time step,
say, h = 0.01seconds
Runge Kutta/Butcher Method
 Has its origins in a 2
variable Taylor Series
Expansion
dy
 f ( x, y )
dx
yi 1  yi   ( xi , yi , h )  h
 The function  ( xi , yi , h) is
called the increment
function
 RK4 is a four factor
expansion of the
incrementing function
 For RK4:
k1 k2 k3 k4
  
6 3 3 6
k1  f ( xi , yi )
 ( xi , yi , h ) 
hk
h
k2  f ( xi  , yi  1 )
2
2
hk
h
k3  f ( xi  , yi  2 )
2
2
k4  f ( xi  h, yi  hk3 )
 Butcher’s method uses 5
factors is more accurate
than RK4 at a given time
step
Example
mx  bx  kx  0
15 x  17 x  50 x  0
assume x = 0.2, x  0 at t=0, h = 0.1
dx
dx
17
50
 x,
 x
x
dt
dt
15
15
1 
 0
 x
d  x

 f ( x, t )  50
17   



dt  x 
   x
15 
 15
note: y  x and x  t for the RK4 formulae
1  0.2   0 
 0
k1  f (ti , xi )  
  0    0.6667 

3.333

1.133

  

1   0.2 
 0
 0    0.0333
hk
h
k2  f (ti  , xi  1 )  

0.05

  
 0.6667     0.629 
2
2
 3.333 1.133   0 

 

1   0.2 
 0
 0.0333   0.0314 
hk
h
k3  f ( xi  , yi  2 )  
    0.05 

    0.625 

3.333

1.133
0

0.629
2
2

  

 

1   0.2 
 0
 0.0314    0.0625
k4  f ( xi  h, yi  hk3 )  

0.1
  
 0.625     0.585 
 3.333 1.133   0 

 

 ( xi , yi , h ) 
k1 k2 k3 k4 1  0  1  0.0333 1  0.0314  1  0.0625  0.0320
   




6 3 3 6 6  0.6667  3  0.629  3  0.625  6  0.585   0.627 
Example
k1 k2 k3 k4 1  0  1  0.0333 1  0.0314  1  0.0625  0.0320
   




6 3 3 6 6  0.6667  3  0.629  3  0.625  6  0.585   0.627 
0.2   0.0320
 0.1968 
yi 1  yi   ( xi , yi , h )  h     
* 0.1  


 0   0.627 
 0.0637 
then we would continue with further iterations
 ( xi , yi , h ) 
The result of the RK4 at h = 0.1 is essentially the same as the analytic solution:
Summary
 Models for Control Systems are either differential equation or
difference equations
 The problems we commonly see will be
 Finding the roots of the equation
 Finding the trajectory or path of the equation over time
 While we have a number of analytical techniques to find exact
results, we cannot address all of the equations encountered
 Numerical methods for finding roots and for trajectories are most
commonly used
 Newton Raphson for finding roots
 Methods such as the Runge Kutta 4 are used for trajectories
Next Class: Analyzing stability
Download