ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 1 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical & Mechanical Engineer Engr/Math/Physics 25 Chp9: ODE’s Numerical Solns
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 2 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Learning Goals List Characteristics of Linear, MultiOrder, NonHomgeneous Ordinary Differential Equations (ODEs) Understand the “Finite-Difference” concept that is Basis for All Numerical ODE Solvers Use MATLAB to determine Numerical Solutions to Ordinary Differential Equations (ODEs)
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 3 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Differential Equations Ordinary Diff Eqn Partial Diff Eqn PDE’s Not Covered in ENGR25 Discussed in More Detail in ENGR45 Examining the ODE, Note that it is: LINEAR → y, dy/dt, d 2 y/dt 2 all raised to Power of 1 2 nd ORDER → Highest Derivative is 2 NONhomogenous → RHS 0; –i.e., y(t) has a FORCING Fcn f(t) has CONSTANT CoEfficients
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 4 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Solving 1 st Order ODEs - 1 Given the Simple ODE with No Zero Order (i.e., “y”) term An INITIAL Condition Can Solve by SEPARATING the VARIABLES Now use the IC in the Limits of Integ. AND Integrating Both Sides Note the use of DUMMY VARIABLES of INTEGRATION α and β
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 5 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Solving 1 st Order ODEs - 2 Integrating Separating The Variables sometimes works for 1 st Order Eqns The Function on the RHS of the 1 st Order ODE is the FORCING Function Function only of t Can be a CONSTANT
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 6 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Solving 1 st Order ODEs - 3 Consider the 1 st Order ODE with a “Zero” Order Term and a Forcing Fcn This is the GENERAL Eqn By Theorems of Linear ODEs Let y p (t) ANY Solution to the General ODE Called the “Particular” Solution y c (t) The Solution to the General Eqn with f(t) = 0 The “Complementary Solution” or the “Natural” (UnForced) Response i.e., y c is the Soln to the “Homogenous” Eqn
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 7 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods 1 st Order Response Eqns Given y p and y c then the TOTAL Solution to the ODE Consider the Case Where the Forcing Function is a Constant f(t) = A Now Solve the ODE in Two Parts for y p & y c For the Particular Soln, Notice that a CONSTANT Fits the Eqn:
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 8 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods 1 st Order Response Eqns cont Sub Into the General (Particular) Eqn y p and dy p /dt Next, Divide the Homogeneous Eqn by ·y c to yield (on whtbd) Next Separate the Variables & Integrate Recognize LHS as a Natural Log; so Next Take “e” to The Power of the LHS & RHS
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 9 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods 1 st Order Response Eqns cont Then is called the TIME CONSTANT Thus the Solution for a Constant Forcing Fcn For This Solution Examine Extreme Cases t = 0 t → The Latter Case is Called the Steady-State Response All Time-Dependent Behavior has dissipated
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 10 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Higher Order, Linear ODE’s The GENERAL Higher Order ODE Where the derivative CoEfficients, the g i (t), may be constants, including Zero IF an analytical Solution Exists Then use the same “linear” methodology as for the First Order Eqn
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 11 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Higher Order, Linear ODE’s Where as Before y c (t) is the solution to Complementary Eqn y p (t) is ANY single solution to the FULL, Orginal Eqn that includes the Force-Fcn e.g.:
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 12 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods For More Info On Higher Order Hi-Order ODEs usually do NOT have Analytical solns, except in special cases Consider a 2 nd order, Linear, NonHomogenous, Constant CoEfficient ODE of the form –ODE’s with these SPECIFIC Characteristics can ALWAYS be Solved Analytically See APPENDIX for more details These Methods used in ENGR43
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 13 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Numerical ODE Solutions Today we’ll do some MTH25 We’ll “look under the hood” of NUMERICAL Solutions to ODE’s The BASIC Game- Plan for even the most Sophisticated Solvers: Given a STARTING POINT, y(0) Use ODE to find the slope dy/dt at t=0 ESTIMATE y 1 as
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 14 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Numerical Solution - 1 Notation Exact Numerical Method (impossible to achieve) by Forward Steps Now Consider slope y n+1 tntn ynyn t n+1 t tt
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 15 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Numerical Solution - 2 The diagram at Left shows that the relationship between y n, y n+1 and the CHORD slope y n+1 tntn ynyn t n+1 t tt The problem with this formula is we canNOT calculate the CHORD slope exactly We Know Only Δt & y n, but NOT the NEXT Step y n+1 The Analyst Chooses Δt Chord Slope Tangent Slope
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 16 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Numerical Solution -3 However, we can calculate the TANGENT slope at any point FROM the differential equation itself 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 Recognize dy/dt as the Tangent Slope
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 17 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Euler Method – 1 st Order Solve 1 st Order ODE with I.C. ReArranging Use: [Chord Slope] [Tangent Slope at start of time step] Then Start the “Forward March” with Initial Conditions
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 18 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 19 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Euler Example Consider 1 st Order ODE with I.C. Use The Euler Forward-Step Reln See Next Slide for the 1 st Nine Steps For Δt = 0.1 But from ODE So In This Example:
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 20 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Euler Exmpl Calc ntntn ynyn f n = – y n +1 y n+1 = y n + t∙f n Plot Slope
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 21 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Euler vs Analytical The Analytical Solution
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 22 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Analytical Soln Let u = −y+1 Then Sub for y & dy in ODE Separate Variables Integrate Both Sides Recognize LHS as Natural Log Raise “e” to the power of both sides
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 23 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Analytical Soln And Thus Soln u(t) Sub u = 1−y Now use IC The Analytical Soln
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 24 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Predictor-Corrector - 1 Again Solve 1 st Order ODE with I.C. Mathematically This Time Let: Chord slope average of tangent slopes at start and END of time step BUT, we do NOT know y n+1 and it appears on the BOTH sides of the Eqn... Avg of the Tangent Slopes at (t n,y n ) & (t n+1,y n+1 )
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 25 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Predictor-Corrector - 2 Use Two Steps to estimate y n+1 First → PREDICT* Use standard Euler Method to Predict Then Correct by using y* in the Avg Calc Then Start the “Forward March” with the Initial Conditions
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 26 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Predictor-Corrector Example Solve ODE with IC The Corrector step The next Step Eqn for dy/dt = f(t,y)= –y+1 Numerical Results on Next Slide
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 27 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Predictor-Corrector Example n Slope
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 28 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Predictor-Corrector Greatly Improved Accuracy
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 29 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods ODE Example: Euler Solution with ∆t = 0.25, y(t=0) = 37 The Solution Table
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 30 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Compare Euler vs. ODE45 Euler SolutionODE45 Solution Euler is Much LESS accurate
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 31 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Compare Again with ∆t = Euler SolutionODE45 Solution Smaller ∆T greatly improves Result
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 32 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods 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)')
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 33 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods MatLAB Command Window for ODE45 >> dydtfcn 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')
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 34 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods All Done for Today Carl Runge Carl David Tolmé Runge Born: 1856 in Bremen, Germany Died: 1927 in Göttingen, Germany
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 35 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical & Mechanical Engineer Engr/Math/Physics 25 Appendix
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 36 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods 2 nd Order Linear Equation Need Solutions to the 2 nd Order ODE As Before The Solution Should Take This form If the Forcing Fcn is a Constant, A, Then Discern a Particular Soln Verify y p Where y p Particular Solution y c Complementary Solution For Any const Forcing Fcn, f(t) = A
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 37 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods The Complementary Solution The Complementary Solution Satisfies the HOMOGENOUS Eqn Look for Solution of this type Need y c So That the “0 th ”, 1 st & 2 nd Derivatives Have the SAME FORM so they will CANCEL (i.e., Divide-Out) in the Homogeneous Eqn Sub Assumed Solution (y = Ge st ) into the Homogenous Eqn Canceling Ge st The Above is Called the Characteristic Equation
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 38 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Complementary Solution cont A value for “s” That SATISFIES the CHARACTERISTIC Eqn ensures that Ge st is a SOLUTION to the Homogeneous Eqn Recall the Homogeneous Eqn If Ge st is indeed a Solution Then Need The Characteristic Eqn Solve For s by Quadratic Eqn In terms of the Discriminant γ
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 39 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Complementary Solution cont.2 Given the “Roots” of the Homogeneous Eqn In the Unstable case the response will grow exponentially toward ∞ This is not terribly interesting If the Solution is Stable, need to Consider three Sets of values for s based on the sign of γ 1. γ > 0 → s 1, s 2 REAL and UNequal roots 2. γ = 0 → s 1 = s 2 = s; ONE REAL root 3. γ < 0 → Two roots as COMPLEX CONJUGATES Can Generate STABLE and UNstable Responses Stable UNstable
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 40 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Complementary Soln Cases 1&2 For the Linear, 2 nd Order, Constant Coeff, Homogenous Eqn By the Methods of MTH4 & ENGR43 Find Solutions to the ODE by discriminant case: 1.Real & Unequal Roots (Stable for Neg Roots) 2.Single Real Root (Stable for Neg Root)
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 41 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Complementary Soln Case - 3 Using the Euler Identity: And Collecting Terms find 3.Complex Conjugate Roots of the form: s = a ± jω (Stable for Neg a) a, ω, B 1, B 2 all Constants (a & ω are KNOWN)
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 42 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods 2 nd Order Solution For the Linear, 2 nd Order, Constant Coeff, Homogenous Eqn Can Find Solution based Upon the nature of the Roots of the Characteristic Eqn To Find the Values of the Constants Need TWO Initial Conditions (ICs) The ZERO Order IC The 1 st Order IC
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 43 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Properly Apply Initial conditions The IC’s Apply ONLY to the TOTAL Solution Many times It’s EASY to forget to add the PARTICULAR solution BEFORE applying the IC’s Do NOT neglect y p (t) prior to IC’s
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 44 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods 2 nd Order ODE Example - 1 The Homogeneous Equation And the IC’s Then the Soln Form Given Real & UnEqual Roots The Characteristic Eqn and Roots
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 45 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods 2 nd Order ODE Example - 2 From the Zero Order IC To Use the 1 st Order IC need to take Derivative Now Have 2 Eqns for A 1 & A 2 Then at t = 0 Solve w/ MATLAB BackDivision
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 46 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods 2nd Order ODE Example - 3 MATLAB session Or The Response Curve >> C = [1,1; -3,-6]; >> b = [0.5; -8.5]; >> A = C\b A = >> A_6 = 6*A A_6 = Be sure to check for correct IC’s Starting-Value & Slope
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 47 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods 2 nd Order ODE SuperSUMMARY-1 See Appendix for FULL Summary Find ANY Particular Solution to the ODE, y p (often a CONSTANT) Homogenize ODE → set RHS = 0 Assume y c = Ge st ; Sub into ODE Find Characteristic Eqn for y c ; a 2 nd order Polynomial
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 48 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods 2 nd Order ODE SuperSUMMARY-2 Find Roots to Char Eqn Using Quadratic Formula (or MATLAB) Examine Nature of Roots to Reveal form of the Eqn for the Complementary Solution: Real & Unequal Roots → y c = Decaying Constants Real & Equal Roots → y c = Decaying Line Complex Roots → y c = Decaying Sinusoid
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 49 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods 2 nd Order ODE SuperSUMMARY-3 Then the TOTAL Solution: y = y c + y p All TOTAL Solutions for y(t) include 2 Unknown Constants Use the Two INITIAL Conditions to generate two Eqns for the 2 unknowns Solve the Total Solution for the 2 Unknowns to Complete the Solution Process
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 50 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods 2 nd Order ODE SUMMARY-1 If NonHomogeneous Then find ANY Particular Solution Next HOMOGENIZE the ODE The Soln to the Homog. Eqn Produces the Complementary Solution, y c Assume y c take this form
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 51 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods 2 nd Order ODE SUMMARY-2 Subbing yc = Ae s t into the Homog. Eqn yields the Characteristic Eqn Find the TWO roots that satisfy the Char Eqn by Quadratic Formula Check FORM of Roots If s 1 & s 2 → REAL & UNequal Decaying Contant(s)
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 52 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods 2 nd Order ODE SUMMARY-3 If s 1 & s 2 → REAL & Equal, then s 1 = s 2 =s Decaying Line If s 1 & s 2 → Complex Conjugates then Decaying Sinusoid Add Particlular & Complementary Solutions to yield the Complete Solution
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 53 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods 2 nd Order ODE SUMMARY-4 To Find Constant Sets: (G 1, G 2 ), (m, b), (B 1, B 2 ) Take for COMPLETE solution Find Number-Values for the constants to complete the solution process Yields 2 eqns in 2 for the 2 Unknown Constants
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 54 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Finite Difference Methods - 1 Another way of thinking about numerical methods is in terms of finite differences. Use the Approximation And From the Differential Eqn From these two equations obtain: Recognize as the Euler Method
ENGR-25_Lec-23_ODEs_Euler_Numerical.pptx 55 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Finite Difference Methods - 2 Could make More Accurate by Approximating dy/dt at the Half-Step as the average of the end pts Recognize as the Predictor-Corrector Method Then Again Use the ODE to Obtain