ENGR-25_Lec-21_Integ_Diff.ppt 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-21_Integ_Diff.ppt 2 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Learning Goals List Characteristics of Linear, MultiOrder, NonHomgeneous Ordinary Differential Equations (ODEs) Solve ANALYTICALLLY, Linear, 2 nd Order, NonHomogeneous, Constant Coefficient ODEs Use MATLAB to determine Numerical Solutions to Ordinary Differential Equations (ODEs)
ENGR-25_Lec-21_Integ_Diff.ppt 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 is NONhomogenous → RHS 0; –i.e., y(t) has a FORCING Fcn f(t) has CONSTANT Coefficients
ENGR-25_Lec-21_Integ_Diff.ppt 4 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Numerical ODE Solution Today we’ll do some MTH25 We’ll “look under the hood” of NUMERICAL Solutions to ODE’s The BASIC Game- Plan for even Sophisticated Solvers: Given a STARTING POINT, y(0) Use ODE to find dy/dt at t=0 ESTIMATE y 1 as
ENGR-25_Lec-21_Integ_Diff.ppt 5 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Numerical Solution - 1 Notation Exact Numerical Method (impossible to achieve) by Forward Steps Now Consider y n+1 tntn ynyn t n+1 t tt
ENGR-25_Lec-21_Integ_Diff.ppt 6 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-21_Integ_Diff.ppt 7 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-21_Integ_Diff.ppt 8 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-21_Integ_Diff.ppt 9 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-21_Integ_Diff.ppt 10 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-21_Integ_Diff.ppt 11 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Euler vs Analytical The Analytical Solution
ENGR-25_Lec-21_Integ_Diff.ppt 12 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-21_Integ_Diff.ppt 13 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-21_Integ_Diff.ppt 14 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 RHS... Avg of the Tangent Slopes at (t n,y n ) & (t n+1,y n+1 )
ENGR-25_Lec-21_Integ_Diff.ppt 15 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Predictor-Corrector - 2 Use Two Steps to estimate y n+1 First → PREDICT* Use y* in the Avg Calc Then Correct Then Start the “Forward March” with the Initial Conditions
ENGR-25_Lec-21_Integ_Diff.ppt 16 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-21_Integ_Diff.ppt 17 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Predictor-Corrector Example n Slope
ENGR-25_Lec-21_Integ_Diff.ppt 18 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Predictor-Corrector Greatly Improved Accuracy
ENGR-25_Lec-21_Integ_Diff.ppt 19 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods ODE Example: Euler Solution with ∆t = 0.25 The Solution Table
ENGR-25_Lec-21_Integ_Diff.ppt 20 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Compare Euler vs. ODE45 Euler SolutionODE45 Solution Euler is Much LESS accurate
ENGR-25_Lec-21_Integ_Diff.ppt 21 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Compare Again with ∆t = Euler SolutionODE45 Solution Smaller ∆T greatly improves Result
ENGR-25_Lec-21_Integ_Diff.ppt 22 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-21_Integ_Diff.ppt 23 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-21_Integ_Diff.ppt 24 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-21_Integ_Diff.ppt 25 Bruce Mayer, PE Engineering/Math/Physics 25: Computational Methods Bruce Mayer, PE Licensed Electrical & Mechanical Engineer Engr/Math/Physics 25 Appendix
ENGR-25_Lec-21_Integ_Diff.ppt 26 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-21_Integ_Diff.ppt 27 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-21_Integ_Diff.ppt 28 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-21_Integ_Diff.ppt 29 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-21_Integ_Diff.ppt 30 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-21_Integ_Diff.ppt 31 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