1 / 22

CMPSC 200 Spring 2013 Lecture 38

CMPSC 200 Spring 2013 Lecture 38. November 18 or 20 , 2013 (depending on section). ODE Examples. There are times when you may need to solve ODE for systems of equations or higher order ODEs.

yan
Download Presentation

CMPSC 200 Spring 2013 Lecture 38

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CMPSC 200 Spring 2013Lecture 38 November 18 or 20 , 2013 (depending on section)

  2. ODE Examples • There are times when you may need to solve ODE for systems of equations or higher order ODEs. • Create a function that accepts two variables as inputs (often t and y) and returns a column vector as output.

  3. Higher Order Differential Equations • Reduce to a system of first order equations. • See example on pages 529 - 531 in your text book

  4. Example of Higher Order ODE • Problem 13.22 in your textbook gives the Blasius equation for laminar flow as = 0 • Let h1 = f, h2 = df/dn, and h3 = d2f/dn2then • dh1/dn = h2, • dh2/dn = h3 • Substitute into the equation and solve for dh3/dn 2 dh3/dn + h1h3 = 0 dh3/dn = -0.5 h1h3

  5. Solution to Problem 13.22 (p 544) • Break into system of equations and put into functionfunctiondhdn = Blasius(n,h)dhdn(1) = h(2); % dh/dn = h2dhdn(2) = h(3); % d2h/dn2 = h3dhdn(2) = -0.5*h(1)*h(3); % d3h/dn3 = -0.5h1h3dhdn= dhdn’

  6. Questions

  7. Roots of Equations • Find value(s) of the independent variable when the dependent variable is 0. (y = X2 – 1 for what values of X is y = 0) • Use graphical methods and ginput. • Use “Bracketing Methods” • Need two “guesses” where the values of the of the dependent variable change signs. Therefore you know that a root is inside range • Slow, but usually work • Use “Open Methods” • Need one or more guesses • Fast, do not always work

  8. Bracketing Methods • Incremental • Move from first guess to second in a series of steps. • Find positions where result of function changes sign • May find a number of ranges for roots • Bisection • Evaluate function at midpoint between two guesses. • If evaluation at midpoint = 0 (or close), then done • If first guess and midpoint have same sign, then repeat with midpoint and second guess. Otherwise repeat with first guess and midpont. • Continue until reach desired precision

  9. Bracketing Methods (cont) • False Position (linear interpolation). • Similar to bisection • Draw a straight line between two guesses. • Use where the line crosses the x-axis as a possibility. • Evaluate function at that possibility. • If evaluation at possibility is 0 or close to 0 stop • Repeat with guess that has opposite sign as possibility.

  10. Algorithm for Incremental Search • Create a vector for x from low guess to high guess with number of increments • Calculate values for f(x) using vector • Set number of roots to 0 • With a loop that goes from k =1 to k = next to last element. • Compare signs f(xk) to f(xk+1) • If signs are different then add 1 to the number of roots and store values of x that bracket that root. • Sign function – returns -1, 0 or 1

  11. Change in sign – record points No change in sign

  12. Function for Incremental Search • Pass function, low value, high value and number of increments to function. • Create a function handle, then use it in the function call. • myfun = @(x) x.^3 – x.^2 – 4*x +4 • incsrch(myfun, -3, 3, 300) • Use the function in the function call • incsrch(@(x) x.^3 – x.^2 – 4*x +4, -3, 3, 300)

  13. Questions ???

  14. Algorithm for Bisection Search Determine the midpoint between the low and high guesses for the independent variable. Evaluate the dependent value at this midpoint. If zero, or within tolerance, record and stop. Else if same sign as f(xlow), change low to the midpoint and repeat Else change high guess to midpoint and repeat

  15. xlow f(xmid) is not to 0 and is the same sign as f(xlow), reset xlow to xmid xmid xhigh xmid xmid xhigh xlow F(xmid is not zero and is the same sign as f(xhigh), reset xhigh to xmid

  16. Function for Binary Search • Pass function, low value, high value and tolerance • Create a function handle, then use it in the function call. • myfun = @(x) x.^3 + 2*x.^2 – x - 2 • bisrch(myfun, -3, 3, 300) • Use the function in the function call • bisrch(@(x) x.^3 + 2*x.^2 – x - 2, -3, 3, 300)

  17. Questions

  18. Bracketing Methods (cont) • False Position (linear interpolation). • Similar to bisection • Draw a straight line between two guesses. • Use where the line crosses the x-axis as a possibility. • Evaluate function at that possibility. • If evaluation at possibility is 0 or close to 0 stop • Repeat with guess that has opposite sign as possibility.

  19. Algorithm for False Position Search • Evaluate function at low and high guess and draw a line between f(xlow) and f(xhigh) to determine the point (xnew), where this line crosses thex-axis • Evaluate the dependent value at xnew • If zero, or within tolerance, record and stop. • Else if same sign as f(xlow), change low guess to the xnew and repeat • Else change high guess to xnew and repeat

  20. F(xnew) is not zero and is the same sign as xhigh, reset xhigh to xnew xhigh xlow xnew xnew xhigh

  21. Function for False Position Search • Pass function, low value, high value and tolerance • Create a function handle, then use it in the function call. • myfun = @(x) x.^3 + 2*x.^2 – x - 2 • falsepos(myfun, -3, 3, 300) • Use the function in the function call • falsepos(@(x) x.^3 + 2*x.^2 – x - 2, -3, 3, 0.001)

  22. Questions ???

More Related