Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chp9: ODE’s Numerical Solns

Similar presentations


Presentation on theme: "Chp9: ODE’s Numerical Solns"— Presentation transcript:

1 Chp9: ODE’s Numerical Solns
Engr/Math/Physics 25 Chp9: ODE’s Numerical Solns Bruce Mayer, PE Licensed Electrical & Mechanical Engineer

2 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)

3 Ordinary Differential Equation (ODE)  What is it?
An Equation that Contains one, or more, ORDINARY DERIVATIVES of ANY ORDER

4 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, d2y/dt2 all raised to Power of 1 2nd ORDER → Highest Derivative is 2 NONhomogenous → RHS  0; i.e., y(t) has a FORCING Fcn f(t) has CONSTANT CoEfficients

5 Solving 1st Order ODEs - 1 Given the Simple ODE with
No Zero Order (i.e., “y”) term An INITIAL Condition AND Integrating Both Sides Now use the IC in the Limits of Integ. Can Solve by SEPARATING the VARIABLES Note the use of DUMMY VARIABLES of INTEGRATION 𝛼 and 𝛽

6 Solving 1st Order ODEs - 2 Integrating
Separating The Variables sometimes works for 1st Order Eqns The Function on the RHS of the 1st Order ODE is the FORCING Function Function only of 𝑡 Can be a CONSTANT

7 Solving 1st Order ODEs - 3 yp(t)  ANY Solution to the General ODE
Called the “Particular” Solution yc(t)  The Solution to the General Eqn with f(t) = 0 The “Complementary Solution” or the “Natural” (UnForced) Response i.e., yc is the Soln to the “Homogenous” Eqn Consider the 1st Order ODE with a “Zero” Order Term and a Forcing Fcn This is the GENERAL Eqn By Theorems of Linear ODEs Let

8 1st Order Response Eqns Given yp and yc then the TOTAL Solution to the ODE Consider the Case Where the Forcing Function is a Constant f(t) = A (e.g.; “13”) Now Solve the ODE in Two Parts for yp & yc For the Particular Soln, Notice that a CONSTANT Fits the Eqn: Do τ*dy/dt + y = 0 solution on board

9 1st Order Response Eqns cont
Sub Into the General (Particular) Eqn yp and dyp/dt Next Separate the Variables & Integrate Recognize LHS as a Natural Log; so Next, Divide the Homogeneous Eqn by 𝜏∙ 𝑦 𝑐 to yield (on whtbd) Next Take “e” to The Power of the LHS & RHS

10 1st Order Response Eqns cont
Then For This Solution Examine Extreme Cases t = 0 t →   is called the TIME CONSTANT Thus the Solution for a Constant Forcing Fcn Recall K1 = A; so find K2 from IC of y(0) = SomeNumber The Latter Case is Called the Steady-State Response All Time-Dependent Behavior has dissipated

11 Higher Order, Linear ODE’s
The GENERAL Higher Order ODE Where the derivative CoEfficients, the gi(t), may be constants, including Zero IF an analytical Solution Exists Then use the same “linear” methodology as for the First Order Eqn

12 Higher Order, Linear ODE’s
Where as Before yc(t) is the solution to Complementary Eqn yp(t) is ANY single solution to the FULL, Orginal Eqn that includes the Force-Fcn e.g.: For Full Solution to the example eqn see: ENGR-25_Ttot_HandODE_Solution_1105.pptx

13 For More Info On Higher Order
Hi-Order ODEs usually do NOT have Analytical solns, except in special cases Consider a 2nd order, Linear, NonHomogenous, Constant CoEfficient, Constant Forcing Fcn 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

14 Numerical ODE Solutions
Next 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 dy/dt (= m) at t=0 ESTIMATE y1 as Note that can regard the Rate-of-Change (RoC) dy/dt as a SLOPE

15 Numerical Solution - 1 Notation
Exact Numerical Method (impossible to achieve) by Forward Steps yn+1 yn Analyst CHOOSES del-t Now Consider t tn tn+1 Dt

16 Numerical Solution - 2 The diagram at Left shows that the relationship between yn, yn+1 and the CHORD slope yn+1 Tangent Slope yn Chord Slope The problem with this formula is we canNOT calculate the CHORD slope exactly We Know Only Δt & yn, but NOT the NEXT Step yn+1 Can Only Make a PROJECTION t tn tn+1 Dt The Analyst Chooses Δt

17 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 𝑑𝑦 𝑑𝑡 as the Tangent Slope

18 Euler Method - 1st Order ODE
Solve 1st Order ODE with I.C. ReArranging Use: [Chord Slope]  [Tangent Slope at start of time step] Then Start the “Forward March” Starting from the Initial Conditions dy/dt = fn(tn)

19 𝑑𝑦 𝑑𝑡 = cosh − 8 𝑡 +7 sin 2𝑡 ∙𝑦 5 𝑒 − 𝑡 3 = SLOPE
5 𝑒 − 𝑡 3 ∙ 𝑑𝑦 𝑑𝑡 2 −7 sin 2𝑡 ∙𝑦= cosh − 8 𝑡 𝑑𝑦 𝑑𝑡 = cosh − 8 𝑡 +7 sin 2𝑡 ∙𝑦 5 𝑒 − 𝑡 3 = SLOPE Use illustrate the “Forward March”. Use slope to project-ahead

20 Example  Euler Estimate
Consider 1st Order ODE with I.C. But from ODE So In This Example: Use The Euler Forward-Step Reln For this ODE yp = 1; then dyc/dt + y = 0 => (dyc/dt)/y = -1 => dyc/y = -1dt => yc = exp(-t) => y = yp + yc = exp(-t) + 1 See Next Slide for the 1st Nine Steps For Δt = 0.1

21 Euler Exmple Calc n tn yn fn= – yn+1 yn+1= yn+Dt fn Plot Dy 0.000
0.000 1.000 0.100 1 0.1 0.900 0.190 2 0.2 0.810 0.271 3 0.3 0.729 0.344 4 0.4 0.656 0.410 5 0.5 0.590 0.469 6 0.6 0.531 0.522 7 0.7 0.478 0.570 8 0.8 0.430 0.613 9 0.9 0.387 0.651 Slope Plot

22 Euler vs Analytical The Analytical Solution

23 Analytical Soln Let u = −y+1 Then Integrate Both Sides
Recognize LHS as Natural Log Sub for y & dy in ODE Raise “e” to the power of both sides by the “Equal Powers” Prop. Separate Variables

24 Analytical Soln And Now use IC The Analytical Soln Thus Soln u(t)
Sub u = 1−y

25 ODE Example: Euler Solution with ∆t = 0.25, y(t=0) = 37
The Solution Table

26 Compare Euler vs. ODE45 Euler is Much LESS accurate Euler Solution
MATLAB ODE45 Solution Will Discuss ODE45 Next Time • Notice difference in VERTICAL scales Euler is Much LESS accurate

27 Compare Again with ∆t = 0.025 Smaller ∆T greatly improves Result
Euler Solution ODE45 Solution Notice that the VERTICAL scales are appox. equal Smaller ∆T greatly improves Result

28 MatLAB Code for Euler ∆t = 0.25
% Bruce Mayer, PE % ENGR25 * 04Jan11 % file = Euler_ODE_Numerical_Example_1201.m % clear; close; clc; 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)')

29 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')

30 Example  Euler Approximation
Use four steps of Δt = 0.1 with Euler’s Method to approximate the solution to With I.C. 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.

31 Example  Euler Approx:
Use I.C. to calculate the Initial Slope Use this slope to Project to the NEW value of yn+1 = yn + Δy: Then the NEW value for y:

32 Example  Euler Approximation
Tabulating the remaining Calculations from ODE The table then DEFINES y = f(t) Thus, for example, y(t=0.3) = 1.685

33 Carl Runge All Done for Today Carl David Tolmé Runge
Gabriel Cramer Born: 31 July 1704 in Geneva, Switzerland Died: 4 Jan 1752 in Bagnols-sur-Cèze, France Gabriel Cramer's father was Jean Isaac Cramer, who was a medical doctor in Geneva, while his mother was Anne Mallet. Jean and Anne had three sons who all went on to academic success. Besides Gabriel, their other two sons were Jean-Antione who followed his father's profession and Jean who became a professor of law. Gabriel certainly moved rapidly through his education in Geneva, and in 1722 while he was still only eighteen years old he was awarded a doctorate having submitted a thesis on the theory of sound. Two years later he was competing for the chair of philosophy at the Académie de Clavin in Geneva. The competition for the chair was between three men; the eldest was Amédée de la Rive while the other two were both young men, Giovanni Ludovico Calandrini who was twenty-one years old and Cramer who was one year younger. The magistrates who were making the appointment favoured the older man with more experience but they were so impressed with brilliant two young men that they thought up a clever plan to enable them to acquire the services of all three. Clearly they were looking to the future and seeing in Cramer and Calandrini two men who would make important future contributions to the Academy. The scheme the magistrates proposed was to split the chair of philosophy into two chairs, one chair of philosophy and one chair of mathematics. De la Rive was offered the philosophy chair, which after all was what he had applied for in the first place, while Cramer and Calandrini were offered the mathematics chair on the understanding that they shared the duties and shared the salary. The magistrates put another condition on the appointment too, namely that Cramer and Calandrini each spend two or three years travelling and while one was away the other would take on the full list of duties and the full salary. It was a good plan for not only did it successfully attract all three men to the Academy, but it also gave Cramer the opportunity to travel and meet mathematicians around Europe and he was to take full advantage of this which both benefited him and the Academy. Cramer and Calandrini divided up the mathematics courses each would teach. Cramer taught geometry and mechanics while Calandrini taught algebra and astronomy. The two had been paired in the arrangement and their friends joking called them Castor and Pollux. Had their personalities been different the arrangement might have presented all sorts of difficulties, but given their natures things worked out remarkably well. Cramer is said to have been [1]:- ... friendly, good-humoured, pleasant in voice and appearance, and possessed of good memory, judgement and health. We must not give the impression that Cramer just fitted into an existing pattern of teaching. He proposed a major innovation, which the Academy accepted, which was that he taught his courses in French instead of Latin, the traditional language of scholars at that time:- ... in order that persons who had a taste for these sciences but no Latin could profit. Appointed in 1724, Cramer followed the conditions of his appointment and set out for two years of travelling in He visited leading mathematicians in many different cities and countries of Europe. He headed straight away for Basel where many leading mathematicians were working, spending five months working with Johann Bernoulli, and also Euler who soon afterwards headed off to St Petersburg to be with Daniel Bernoulli. Cramer then visited England where he met Halley, de Moivre, Stirling, and other mathematicians. His discussions with these mathematicians and the continuing correspondence with them after he returned to Geneva had a big influence on Cramer's work. From England Cramer made his way to Leiden where he met 'sGravesande, then he moved on to Paris where he had discussions with Fontenelle, Maupertuis, Buffon, Clairaut, and others. These two years of travelling were to set the tone for Cramer's career for he was highly regarded by all the mathematicians he met, he corresponded with them throughout his life, and he was to perform many extremely valuable major tasks as an editor of their works. Back in Geneva in 1729, Cramer was at work on an entry for the prize set by the Paris Academy for 1730, which was "Quelle est la cause de la figure elliptique des planètes et de la mobilité de leurs aphélies?" Cramer's entry was judged as the second best of those received by the Academy, the prize being won by Johann Bernoulli. In 1734 the "twins" split up when Calandrini was appointed to the chair of philosophy and Cramer became the sole holder of the Chair of Mathematics. Cramer lived a busy life, for in addition to his teaching and correspondence with many mathematicians, he produced articles of considerable interest although these are not of the importance of the articles written by most of the top mathematicians with whom he corresponded. He published articles in various places including the Memoirs of the Paris Academy in 1734, and of the Berlin Academy in 1748, 1750 and The articles cover a wide range of subjects including the study of geometric problems, the history of mathematics, philosophy, and the date of Easter. He published an article on the aurora borealis in the Philosophical Transactions of the Royal Society of London and he also wrote an article on law where he applied probability to demonstrate the significance of having independent testimony from two or three witnesses rather than from a single witness. His work was not confined to academic areas for he was also interested in local government and served as a member of the Council of Two Hundred in 1734 and of the Council of Seventy in His work on these councils involved him using his broad mathematical and scientific knowledge, for he undertook tasks involving artillery, fortification, reconstruction of buildings, excavations, and he acted as an archivist. He made a second trip abroad in 1747, this time only visiting Paris where he renewed his friendship with Fontenelle as well as meeting d'Alembert. There are two areas of Cramer's mathematical work which we should highlight. This is the editorial work which he undertook and also his major mathematical work Introduction à l'analyse des lignes courbes algébriques published in 1750. Johann Bernoulli died in 1748, only three or so years before Cramer, but he arranged for Cramer to publish his Complete Works before his death. It shows how much respect Bernoulli had for Cramer that he insisted that no other edition of his works be published by any editor other than Cramer. Johann Bernoulli's Complete Works was published by Cramer in four volumes in Not only did Johann Bernoulli arrange for Cramer to publish his Complete Works but he also requested that he edit Jacob Bernoulli's works. Jacob Bernoulli had died 1705 and Cramer published his Works in two volumes in These are not complete since Ars conjectandi is omitted, but the volumes do contain previously unpublished material and the mathematical background necessary to understand them. In 1745, jointly with Johann Castillon, Cramer published the correspondence between Johann Bernoulli and Leibniz. Cramer also edited the five volume work by Christian Wolff, first published between 1732 and 1741 with a new edition appearing between 1743 and 1752. Finally we should describe Cramer's most famous book Introduction à l'analyse des lignes courbes algébraique. It is a work which Cramer modelled on Newton's memoir on cubic curves and he praises highly a commentary on Newton's memoir written by Stirling. He also comments that had he known of Euler's Introductio in analysin infinitorum earlier he would have made great use of it. Of course Euler's book was only published in 1748 at which time much of Cramer's book might well have been written. Jones writes in [1]:- That he made little use of Euler's work is supported by the rather surprising fact that throughout his book Cramer makes essentially no use of the infinitesimal calculus in either Leibniz' or Newton's form, although he deals with such topics as tangents, maxima and minima, and curvature, and cites Maclaurin and Taylor in footnotes. One conjectures that he never accepted or mastered the calculus. The suggestion that Cramer never mastered the calculus must be considered doubtful, particularly given the high regard that he was held in by Johann Bernoulli. After an introductory chapter in which types of curves are defined and techniques for drawing their graphs are discussed, Cramer goes on to a second chapter in which transformations to simplify curves are studied. The third chapter looks at a classification of curves and it is in this chapter that the now famous "Cramer's rule" is given. After giving the number of arbitrary constants in an equation of degree n as n2/2 + 3n/2, he deduces that an equation of degree n can be made to pass through n points. Taking n = 5 he gives an example of finding the five constants involved in making an equation of degree 2 pass through 5 points. This leads to 5 linear equations in 5 unknowns and he refers the reader to an appendix containing Cramer's rule for their solution. We should remark, of course, that Cramer was certainly not the first to give this rule. The other "well known" part of Cramer's work is his description of Cramer's paradox. He states a theorem by Maclaurin which says that an equation of degree n intersects an equation of degree m in nm points. Taking n = m = 3 this says that two cubics intersect in 9 points, yet his own formula n2/2 + 3n/2 with n = 3 gives 9 so a cubic is uniquely determined by 9 points. This, says Cramer, is a paradox, but his attempt to explain the paradox is incorrect. Cramer's name has sometimes been attached to another problem, namely the Castillon-Cramer problem. This problem, proposed by Cramer to Castillon, asked how to inscribe a triangle in a circle so that it passed through three given points. Castillon solved the problem 25 years after Cramer's death, and the problem went on to various generalisations about inscribed polygons in a conic section. Cramer had worked extremely hard over a long period with writing his Introduction à l'analyse and undertaking the large amount of editorial work in addition to all his normal duties. Always of good health, this overwork coupled with a fall from his carriage, brought on a sudden decline. He spent two months in bed recovering, and his doctor then recommended that he spend a quiet period in the south of France to completely regain his strength. Leaving Geneva on 21 December 1751 he began his journey but he died two weeks later while still on the journey. Article by: J J O'Connor and E F Robertson Carl David Tolmé Runge Born: 1856 in Bremen, Germany Died: 1927 in Göttingen, Germany

34 Licensed Electrical & Mechanical Engineer BMayer@ChabotCollege.edu
Engr/Math/Physics 25 Appendix Time For Live Demo Bruce Mayer, PE Licensed Electrical & Mechanical Engineer 𝑒 − 𝑡 3 𝑑 3 𝑦 𝑑𝑡 3 − 3 𝑥 𝑑 2 𝑦 𝑑𝑡 𝑑𝑦 𝑑𝑡 −7 sin 2𝑡 = cosh − 8 𝑡

35 2nd Order Linear Equation
Need Solutions to the 2nd Order ODE If the Forcing Fcn is a Constant, A, Then Discern a Particular Soln As Before The Solution Should Take This form Verify yp Where yp  Particular Solution yc  Complementary Solution For Any const Forcing Fcn, f(t) = A

36 The Complementary Solution
The Complementary Solution Satisfies the HOMOGENOUS Eqn Look for Solution of this type Sub Assumed Solution (y = Gest) into the Homogenous Eqn Need yc So That the “0th”, 1st & 2nd Derivatives Have the SAME FORM so they will CANCEL (i.e., Divide-Out) in the Homogeneous Eqn Canceling Gest The Above is Called the Characteristic Equation

37 Complementary Solution cont
A value for “s” That SATISFIES the CHARACTERISTIC Eqn ensures that Gest is a SOLUTION to the Homogeneous Eqn Recall the Homogeneous Eqn The Characteristic Eqn Solve For s by Quadratic Eqn In terms of the Discriminant γ If Gest is indeed a Solution Then Need

38 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 → s1, s2 REAL and UNequal roots 2. γ = 0 → s1 = s2 = s; ONE REAL root 3. γ < 0 → Two roots as COMPLEX CONJUGATES Can Generate STABLE and UNstable Responses Stable For Unstable case, c ExOr m would need to a negative number UNstable

39 Complementary Soln Cases 1&2
For the Linear, 2nd Order, Constant Coeff, Homogenous Eqn By the Methods of MTH4 & ENGR43 Find Solutions to the ODE by discriminant case: Real & Unequal Roots (Stable for Neg Roots) Single Real Root (Stable for Neg Root)

40 Complementary Soln Case - 3
Complex Conjugate Roots of the form: s = a ± jω (Stable for Neg a) Using the Euler Identity: And Collecting Terms find Parameter a will be a NEGATIVE number: a = -c/2m a, ω, B1, B2 all Constants (a & ω are KNOWN)

41 2nd Order Solution For the Linear, 2nd Order, Constant Coeff, Homogenous Eqn To Find the Values of the Constants Need TWO Initial Conditions (ICs) The ZERO Order IC Can Find Solution based Upon the nature of the Roots of the Characteristic Eqn The 1st Order IC

42 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 yp(t) prior to IC’s

43 2nd Order ODE Example - 1 The Homogeneous Equation
The Characteristic Eqn and Roots And the IC’s Then the Soln Form Given Real & UnEqual Roots Units for y & t are, say, FEET & MINUTES

44 2nd Order ODE Example - 2 From the Zero Order IC Then at t = 0
To Use the 1st Order IC need to take Derivative Now Have 2 Eqns for A1 & A2 Solve w/ MATLAB BackDivision

45 Be sure to check for correct IC’s  Starting-Value & Slope
2nd Order ODE Example - 3 MATLAB session The Response Curve >> C = [1,1; -3,-6]; >> b = [0.5; -8.5]; >> A = C\b A = 2.3333 >> A_6 = 6*A A_6 = Be sure to check for correct IC’s  Starting-Value & Slope Or

46 2nd Order ODE SuperSUMMARY-1
See Appendix for FULL Summary Find ANY Particular Solution to the ODE, yp (often a CONSTANT) Homogenize ODE → set RHS = 0 Assume yc = Gest; Sub into ODE Find Characteristic Eqn for yc; a 2nd order Polynomial

47 2nd 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 → yc = Decaying Constants Real & Equal Roots → yc = Decaying Line Complex Roots → yc = Decaying Sinusoid

48 2nd Order ODE SuperSUMMARY-3
Then the TOTAL Solution: y = yc + yp 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

49 2nd Order ODE SUMMARY-1 If NonHomogeneous Then find ANY Particular Solution The Soln to the Homog. Eqn Produces the Complementary Solution, yc Assume yc take this form Next HOMOGENIZE the ODE

50 2nd Order ODE SUMMARY-2 Subbing yc = Aest into the Homog. Eqn yields the Characteristic Eqn Check FORM of Roots If s1 & s2 → REAL & UNequal Find the TWO roots that satisfy the Char Eqn by Quadratic Formula Decaying Contant(s)

51 2nd Order ODE SUMMARY-3 If s1 & s2 → REAL & Equal, then s1 = s2 =s
Decaying Sinusoid Add Particlular & Complementary Solutions to yield the Complete Solution Decaying Line If s1 & s2 → Complex Conjugates then

52 2nd Order ODE SUMMARY-4 To Find Constant Sets: (G1, G2), (m, b), (B1, B2) 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

53 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

54 Finite Difference Methods - 2
Could make More Accurate by Approximating dy/dt at the Half-Step as the average of the end pts Then Again Use the ODE to Obtain Recognize as the Predictor-Corrector Method


Download ppt "Chp9: ODE’s Numerical Solns"

Similar presentations


Ads by Google