§9.4 ODE Analytics Chabot Mathematics Bruce Mayer, PE

advertisement
Chabot Mathematics
§9.4 ODE
Analytics
Bruce Mayer, PE
Licensed Electrical & Mechanical Engineer
BMayer@ChabotCollege.edu
Chabot College Mathematics
1
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Review §
9.3
 Any QUESTIONS About
• §9.3 Differential Equation Applications
 Any QUESTIONS
About HomeWork
• §9.3 → HW-15
Chabot College Mathematics
2
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
§9.4 Learning Goals
 Analyze solutions of
differential equations
using slope fields
 Use Euler’s method
for approximating
solutions of initial
value problems
Chabot College Mathematics
3
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Slope Fields
 Recall that indefinite integration, or
AntiDifferentiation, is the process of
finding a function from its derivative only
• In other words, if we have a derivative, the
AntiDerivative allows us to regain the
function before it was differentiated –
EXCEPT for the CONSTANT, of course.
 Given the derivative dy/dx = f ‘(x) then
solving for y (or f(x)), produces the
General Solution of a Differential Eqn
Chabot College Mathematics
4
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Slope Fields
 AntiDifferentiation (Separate Variables)
Example
 dy

dy
 2x
• Let:
dx
  2 x dx
 dx

• Then Separating the Variables: dy  2 x dx
• Now take the AntiDerivative:  dy   2 x dx
• To Produce the General Solution: y  x  C
2
 This Method Produces an EXACT and
SYMBOLIC Solution which is also
called an ANALYTICAL Solution
Chabot College Mathematics
5
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Slope Fields
 Slope Fields, on the other hand,
provide a Graphical Method for ODE
Solution
 Slope, or Direction, fields basically draw
slopes at various CoOrdinates for
differing values of the BC/IC constant C.
 Example: The
Slope Field dy

x
for ODE
dx
Chabot College Mathematics
6
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Slope Fields
 The slope field 𝑑𝑦 𝑑𝑥 = 𝑥
describes several different
parabolas based on
varying values of C
0, 𝐶 is the Vertex Pt
dy
x2
 x   1  dy   x  dx  y 
C
dx
2
 Slope Field Example:
dy x
create the slope field

for the Ordinary
dx y
Differential Equation:
Chabot College Mathematics
7
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Slope Fields
 Note that dy/dx = x/y calculates the
slope at any (x,y) CoOrdinate point
• At (x,y) = (−2, 2),
dy/dx = −2/2 = −1
• At (x,y) = (−2, 1),
dy/dx = −2/1 = −2
• At (x,y) = (−2, 0),
dy/dx = −2/0 = UnDef.
• And SoOn
y
2
1
x
-2
-1
1
-1
-2
 Produces OutLine of a HYPERBOLA
Chabot College Mathematics
8
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
2
Slope Fields
 Of course this Variable Separable ODE
can be easily solved analytically
dy x
  y dy  x dx
dx y
 y dy   x dx
y
2
1
x
-2
-1
1
-1
-2
Chabot College Mathematics
9
2
1 2 1 2
y  x C
2
2
y2  x2  C
x2  y2  C
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Slope Fields  Example
 For the given slope field, sketch two
approximate solutions – one of which is
dy dx  m  x 2  1
passes through (4,2):
• Solve ODE Analytically using
using (4,2) BC
m
1

dy 1
 x  1  dy   x  1dx
dx 2
2

1

dy

x

1
   2  dx
1
y  x 2  x  C now use BC (4,2)
4
1 2
2  4   4  C  2  C Soln
4
Chabot College Mathematics
10
4,2
y
1 2
x x2
4
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Slope Field Identification
Match the correct DE with its graph:
dy
H dx  y  2
1. _____
A
B
dy
 x3
F dx
2. _____
dy
 sin x
3. _____
D dx
C
E
dy
 y  y  1
B dx
8. _____
Chabot College Mathematics
11
G
If isoclines (points with the same
slope) are along horizontal lines,
then DE depends only on y
ii)
Do you know a slope at a particular
point?
iii)
If we have the same slope along
vertical lines, then DE depends only
on x
iv)
Is the slope field sinusoidal?
v)
What x and y values make the slope
0, 1, or undefined?
vi)
dy/dx = a(x ± y) has similar slopes
along a diagonal.
vii)
Can you solve the separable DEs?
F
dy
 x y
G dx
6. _____
dy
x

E dx y
7. _____
i)
D
dy
 cos x
C dx
4. _____
dy
 x2  y2
A dx
5. _____
In order to determine a slope field
from a differential equation, we
should consider the following:
H
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Example  Demand Slope Field
 Imagine that the change in
fraction of a production facility’s
inventory that is demanded, dD = ( D -1) e- p
dp
D, each period is given by
• Where p is the unit price in $k
 Draw a slope field to approximate a
solution assuming a half-stocked (50%)
inventory and $2k per item, and then
• Verify the Slope-Field solution using
Separation of Variables.
Chabot College Mathematics
c
12
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Example  Demand Slope Field
 SOLUTION:
 Calculate some
Slope Values from
dD
 m  D  1e  p
dp
dD
0,0   m  0  1e 0  1
dp
dD
1,1   m  1  1e 1  0
dp
dD
2,0.5   m  0.5  1e 2  0.068
dp
Chabot College Mathematics
13
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Example  Demand Slope Field
D p  fractional
 An approximate
solution passing
through (2,0.5)
with slope field
on the window
0 < x < 3 and
0<y<1
Chabot College Mathematics
14
p $k/unit 
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Example  Demand Slope Field
 Find an exact solution to this differential
equation using separation of variables:
ò
dD
= ( D -1) e- p
dp
dD
= ò e- p dp
D -1
dD
= e- p dp
D -1
-p
ln D -1 = -e + C
 Remove absolute-value and then
change signs as inventory % demanded
satisfies: 0≤ D ≤1
Chabot College Mathematics
15
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Example  Demand Slope Field
 Removing ABS Bars
ln D  1  e
p
 
D 1  e e
C
C  e
e p
ln D 1
e
 e  p C

D 1  e
e p
 with 0  D  1  1  D  Ae
-e- p
e p
 Or D(p) =1- Ae
 Now use Boundary Value ($2k/unit,0.5)
D(2) =1- Ae
Ae
-e-2
 e 2
= 0.5
A  0.5e
Chabot College Mathematics
16
 
 0.5  A  0.5 e
e 2
 e 2
 0.572
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
 eC
Example  Demand Slope Field
 Graph for D p   1  0.572e
e p
 This is VERY SIMILAR to the Slope
Field Graph Sketched Before
Chabot College Mathematics
17
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Numerical ODE Solutions
 Next We’ll “look
under the hood” of
NUMERICAL
Solutions to ODE’s
 The BASIC GamePlan for even the
most Sophisticated
Solvers:
• Given a STARTING
POINT, y(0)
• Use ODE to find
dy/dt (= m) at t=0
• ESTIMATE y1 as
dy
y1  y0  t 
dt t 0
Chabot College Mathematics
18
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Numerical Solution - 1
 Notation
n  Step Number
t  Time Step Length
tn  n  t
 Exact Numerical
Method (impossible
to achieve) by
Forward Steps
yn+1
y n  y (t n )
f n  f (t n , y n )
yn
 Now Consider
dy
 f (t , y )
dt
Chabot College Mathematics
19
tn
t
tn+1
t
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Numerical Solution - 2
yn+1
Tangent
Slope
yn
Chord
Slope
tn
t
tn+1
The Analyst
Chooses Δt
Chabot College Mathematics
20
 The diagram at Left shows
that the relationship between
yn, yn+1 and the CHORD slope
y n1  y n
 chord slope
t
 The problem with this formula
is we canNOT calculate the
t
CHORD slope exactly
• We Know Only Δt & yn, but
NOT the NEXT Step yn+1
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Numerical Solution - 3
 However, we can
calculate the
TANGENT slope at
any point FROM the
differential equation
itself
dy
mn 
 f (t n , yn )
dt t  t n
 Recognize dy/dt as
the Tangent Slope
tangent slope  f (t , y )
Chabot College Mathematics
21
 The Basic Concept
for all numerical
methods for solving
ODE’s is to use the
TANGENT slope,
available from the
R.H.S. of the ODE,
to approximate the
chord slope
yn 1  yn dy

 f t n , yn 
t
dt tn
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Euler Method - 1st Order ODE
 Solve 1st Order ODE
with I.C.
dy
 f (t , y )
dt
y ( 0)  b
 Use: [Chord Slope]
 [Tangent Slope at
start of time step]
 ReArranging
 dy 
  yn or
yn 1   t
 dt t 
n 

yn 1  y   yn
or
yn 1  t  f n  yn
 Then Start the
“Forward March”
with Initial
yn 1  yn dy
Conditions

 f t n , yn 
t
dt
Chabot College Mathematics
22
tn
t0  0
y0  b
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Example  Euler Estimate
 Consider 1st Order
ODE with I.C.
dy
  y  1  f t , y 
dt
y (t  0)  0
 Use The Euler
Forward-Step Reln
yn 1  yn  t f n
t dy
 yn 
1 dt tn
Chabot College Mathematics
23
 But from ODE
dy
  yn  1
dt t n
 So In This Example:
yn1  yn  t (  yn  1)
 See Next Slide for
the 1st Nine Steps
 yn  yn
For Δt = 0.1
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Euler Exmple Calc
dy
  y  1 t  0.1
dt
y
tn
yn
fn= – yn+1
yn+1= yn+t fn
0
0
0.000
1.000
0.100
1
0.1
0.100
0.900
0.190
2
0.2
0.190
0.810
0.271
3
0.3
0.271
0.729
0.344
4
0.4
0.344
0.656
0.410
5
0.5
0.410
0.590
0.469
6
0.6
0.469
0.531
0.522
7
0.7
0.522
0.478
0.570
8
0.8
0.570
0.430
0.613
9
0.9
0.613
0.387
0.651
n
Slope
Plot
Chabot College Mathematics
24
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Euler vs Analytical
0.8
 The Analytical
Solution
0.6
y  1 e
y
0.4
Numerical
0.2
Exact
1.25
1
0.75
0.5
0.25
0
0
t
Chabot College Mathematics
25
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
t
Analytical Soln
dy
  y  1 y t  0   0
dt
 Let u = −y+1
 Integrate Both Sides
 Then
u  1 y
du dy  0  1
dy  du
 Sub for y & dy in
ODE  du
dt
u
du
 Separate
  dt
Variables u
Chabot College Mathematics
26
du
 u   1dt
 Recognize LHS as
Natural Log
ln u  t  C
 Raise “e” to the
power of both sides
e
ln u
e
t C
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Analytical Soln
dy
  y  1 y t  0   0
dt
 And
 Now use IC
e
e
ln u
u
t  C
C t
 e e  Ke
 Thus Soln u(t)
u  Ke
t
t
0
1  0  Ke
 K 1
 The Analytical Soln
1  y  1 e
t
 Sub u = 1−y
1  y  Ke
Chabot College Mathematics
27
t
y  1 e
t
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
dy
 3.9 cos4.2 y   ln 5.1t  6 
dt
ODE Example:
 Euler Solution with
 The Solution Table
∆t = 0.25, y(t=0) = 37
Euler Solution to dy/dt = 3.9cos(4.2y)-ln(5.1t+6)
38
36
34
y(t) by Euler
32
30
28
26
24
22
0
1
2
3
4
5
t
Chabot College Mathematics
28
6
7
8
9
10
n
t
y
dy/dt
dely
yn+1
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
0
0.25
0.5
0.75
1
1.25
1.5
1.75
2
2.25
2.5
2.75
3
3.25
3.5
3.75
4
4.25
4.5
4.75
5
5.25
5.5
5.75
6
6.25
6.5
6.75
7
7.25
7.5
7.75
8
8.25
8.5
8.75
9
9.25
9.5
9.75
10
37.0000
36.5636
36.9143
36.5769
36.8872
36.5806
36.8418
36.6641
36.9608
36.3357
35.6768
35.2701
35.2882
35.2273
35.3380
35.0526
35.0491
35.0223
34.8909
34.2399
33.9524
33.1997
32.4496
31.6958
30.9492
30.1897
29.4564
28.6710
27.9981
27.1110
26.6745
25.9565
25.3424
25.2245
24.6604
24.6512
24.6268
24.5593
24.2973
23.3007
23.0678
-1.7457
1.4027
-1.3492
1.2410
-1.2264
1.0448
-0.7108
1.1868
-2.5004
-2.6357
-1.6265
0.0722
-0.2436
0.4430
-1.1420
-0.0139
-0.1072
-0.5255
-2.6041
-1.1497
-3.0108
-3.0006
-3.0151
-2.9862
-3.0384
-2.9328
-3.1419
-2.6916
-3.5484
-1.7458
-2.8722
-2.4562
-0.4717
-2.2562
-0.0369
-0.0977
-0.2699
-1.0481
-3.9863
-0.9318
-1.0551
-0.4364
0.3507
-0.3373
0.3103
-0.3066
0.2612
-0.1777
0.2967
-0.6251
-0.6589
-0.4066
0.0181
-0.0609
0.1107
-0.2855
-0.0035
-0.0268
-0.1314
-0.6510
-0.2874
-0.7527
-0.7502
-0.7538
-0.7466
-0.7596
-0.7332
-0.7855
-0.6729
-0.8871
-0.4365
-0.7180
-0.6141
-0.1179
-0.5641
-0.0092
-0.0244
-0.0675
-0.2620
-0.9966
-0.2329
-0.2638
36.5636
36.9143
36.5769
36.8872
36.5806
36.8418
36.6641
36.9608
36.3357
35.6768
35.2701
35.2882
35.2273
35.3380
35.0526
35.0491
35.0223
34.8909
34.2399
33.9524
33.1997
32.4496
31.6958
30.9492
30.1897
29.4564
28.6710
27.9981
27.1110
26.6745
25.9565
25.3424
25.2245
24.6604
24.6512
24.6268
24.5593
24.2973
23.3007
23.0678
22.8040
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Compare Euler vs. ODE45
Euler Solution
ODE45 Solution
Euler Solution to dy/dt = 3.9cos(4.2y)-ln(5.1t+6)
37.5
38
36
37
34
36.5
Y by ODE45
y(t) by Euler
32
30
36
28
35.5
26
35
24
22
0
1
2
3
4
5
t
6
7
8
9
10
34.5
0
1
2
3
4
6
5
T by ODE45
Euler is Much LESS accurate
Chabot College Mathematics
29
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
7
8
9
10
Compare Again with ∆t = 0.025
Euler Solution
ODE45 Solution
Euler Solution to dy/dt = 3.9cos(4.2y)-ln(5.1t+6)
37.5
37.2
37
37
36.8
Y by ODE45
y(t) by Euler
36.5
36.6
36.4
36
35.5
36.2
35
36
35.8
34.5
0
1
2
3
4
5
t
6
7
8
9
10
0
1
2
3
4
6
5
T by ODE45
Smaller ∆t greatly improves Result
Chabot College Mathematics
30
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
7
8
9
10
MatLAB Code for Euler
% Bruce Mayer, PE
% ENGR25 * 04Jan11
% file = Euler_ODE_Numerical_Example_1201.m
%
y0= 37;
delt = 0.25;
t= [0:delt:10];
n = length(t);
yp(1) = y0; % vector/array indices MUST start at 1
tp(1) = 0;
for k = 1:(n-1) % fence-post adjustment to start at 0
dydt = 3.9*cos(4.2*yp(k))^2-log(5.1*tp(k)+6);
dydtp(k) = dydt % keep track of tangent slope
tp(k+1) = tp(k) + delt;
dely = delt*dydt
delyp(k) = dely
yp(k+1) = yp(k) + dely;
end
plot(tp,yp, 'LineWidth', 3), grid, xlabel('t'),ylabel('y(t) by Euler'),...
title('Euler Solution to dy/dt = 3.9cos(4.2y)-ln(5.1t+6)')
Chabot College Mathematics
31
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
MatLAB Command Window for
ODE45
>> dydtfcn = @(tf,yf) 3.9*(cos(4.2*yf))^2-log(5.1*tf+6);
>> [T,Y] = ode45(dydtfcn,[0 10],[37]);
>> plot(T,Y, 'LineWidth', 3), grid, xlabel('T by ODE45'),
ylabel('Y by ODE45')
Chabot College Mathematics
32
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Example  Euler Approximation
 Use four steps of Δt = 0.1 with Euler’s
Method to approximate the solution to
dy
1
2
=y +
dt
t+y
• With I.C. yt  0  1
 SOLUTION:
 Make a table of values, keeping track
of the current values of t and y, the
derivative at that point, and the
projected next value.
Chabot College Mathematics
33
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Example  Euler Approximation
 Use I.C. to calculate the Initial Slope
x0 , y0   0,1

dy
rise
1
2
m
1 
2
dt
run
0 1
 Use this slope to Project to the NEW
value of yn+1 = yn + Δy:
dy
m  t  y  t   t  y  2  0.1  0.2
dt
 Then the NEW value for y:
y1 
Chabot College Mathematics
34
y0  y0
 1  0.2  1.2
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Example  Euler Approximation
 Tabulating the remaining Calculations
y
t
1
0
0.1 1.2
0.2 1.421
0.3 1.685
0.4 2.019
dy dt
dy dt  h  y
y  y
2 × 0.1= 0.2
1.2
2
2.20923 0.220923 1.420923
2.63614 0.263614 1.684614
3.3418
0.33418 2.018794
 The table then DEFINES y = f(t)
 Thus, for example, y(t=0.3) = 1.685
Chabot College Mathematics
35
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
WhiteBoard Work
 Problems From §9.4
• P32 Population Extinction
Chabot College Mathematics
36
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
All Done for Today
Carl
Runge
Carl David Tolmé Runge
Born: 1856 in
Bremen, Germany
Chabot College Mathematics
37
Died: 1927 in
Göttingen, Germany
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Chabot Mathematics
Appendix
r  s  r  s r  s 
2
2
Bruce Mayer, PE
Licensed Electrical & Mechanical Engineer
2a
–
Chabot College Mathematics
38
BMayer@ChabotCollege.edu
2b
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Chabot College Mathematics
39
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Chabot College Mathematics
40
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Chabot College Mathematics
41
Bruce Mayer, PE
BMayer@ChabotCollege.edu • MTH16_Lec-14_sec_9-4_ODE_SlopeFields_Euler.pptx
Download