math 211 math 211
play

Math 211 Math 211 Lecture #14 M ATLAB s ODE Solvers September 26, - PowerPoint PPT Presentation

1 Math 211 Math 211 Lecture #14 M ATLAB s ODE Solvers September 26, 2003 2 Matlab Solvers Matlab Solvers M ATLAB has several solvers. Return 2 Matlab Solvers Matlab Solvers M ATLAB has several solvers. ode45 Return 2 Matlab Solvers


  1. 1 Math 211 Math 211 Lecture #14 M ATLAB ’s ODE Solvers September 26, 2003

  2. 2 Matlab Solvers Matlab Solvers M ATLAB has several solvers. Return

  3. 2 Matlab Solvers Matlab Solvers M ATLAB has several solvers. • ode45 Return

  4. 2 Matlab Solvers Matlab Solvers M ATLAB has several solvers. • ode45 � This is the first choice. Return

  5. 2 Matlab Solvers Matlab Solvers M ATLAB has several solvers. • ode45 � This is the first choice. • ode23 Return

  6. 2 Matlab Solvers Matlab Solvers M ATLAB has several solvers. • ode45 � This is the first choice. • ode23 � This is a good second choice. Return

  7. 2 Matlab Solvers Matlab Solvers M ATLAB has several solvers. • ode45 � This is the first choice. • ode23 � This is a good second choice. • Stiff solvers for equations/systems with widely different time scales. Return

  8. 2 Matlab Solvers Matlab Solvers M ATLAB has several solvers. • ode45 � This is the first choice. • ode23 � This is a good second choice. • Stiff solvers for equations/systems with widely different time scales. � ode15s Return

  9. 2 Matlab Solvers Matlab Solvers M ATLAB has several solvers. • ode45 � This is the first choice. • ode23 � This is a good second choice. • Stiff solvers for equations/systems with widely different time scales. � ode15s • All use the same syntax. Return

  10. 3 ode45 ode45 Return Solvers

  11. 3 ode45 ode45 • Uses variable step size. Return Solvers

  12. 3 ode45 ode45 • Uses variable step size. � Specify error tolerance instead of step size. Return Solvers

  13. 3 ode45 ode45 • Uses variable step size. � Specify error tolerance instead of step size. � M ATLAB chooses the step size at each step to achieve the limit on the error. Return Solvers

  14. 3 ode45 ode45 • Uses variable step size. � Specify error tolerance instead of step size. � M ATLAB chooses the step size at each step to achieve the limit on the error. � The default tolerance is good enough for this course. Return Solvers

  15. 3 ode45 ode45 • Uses variable step size. � Specify error tolerance instead of step size. � M ATLAB chooses the step size at each step to achieve the limit on the error. � The default tolerance is good enough for this course. • Syntax Return Solvers

  16. 3 ode45 ode45 • Uses variable step size. � Specify error tolerance instead of step size. � M ATLAB chooses the step size at each step to achieve the limit on the error. � The default tolerance is good enough for this course. • Syntax [t,y] = ode45(derfile, [ t 0 , t f ] , y 0 ); Return Solvers

  17. 3 ode45 ode45 • Uses variable step size. � Specify error tolerance instead of step size. � M ATLAB chooses the step size at each step to achieve the limit on the error. � The default tolerance is good enough for this course. • Syntax [t,y] = ode45(derfile, [ t 0 , t f ] , y 0 ); plot(t,y) Return Solvers

  18. 4 Solving Systems Solving Systems Return

  19. 4 Solving Systems Solving Systems • Example: x ′ = v v ′ = − 9 . 8 − 0 . 04 v | v | Return

  20. 4 Solving Systems Solving Systems • Example: x ′ = v v ′ = − 9 . 8 − 0 . 04 v | v | • Change to vector notation. (Use M ATLAB vector notation) Return

  21. 4 Solving Systems Solving Systems • Example: x ′ = v v ′ = − 9 . 8 − 0 . 04 v | v | • Change to vector notation. (Use M ATLAB vector notation) � u(1) = x Return

  22. 4 Solving Systems Solving Systems • Example: x ′ = v v ′ = − 9 . 8 − 0 . 04 v | v | • Change to vector notation. (Use M ATLAB vector notation) � u(1) = x � u(2) = v Return

  23. 5 Derivative m-file ball.m Derivative m-file ball.m function upr = ball(t,u) x = u(1); v = u(2); xpr = v; vpr = -9.8 - 0.04*v*abs(v); upr = [xpr; vpr]; Return System

  24. 6 Derivative m-file ballshort.m Derivative m-file ballshort.m function upr = ballshort(t,u) upr = zeros(2,1); upr(1) = u(2); upr(2) = -9.8 - 0.04*u(2)*abs(u(2)); Return System ball.m

  25. 7 Computing and Plotting Solutions to Systems Computing and Plotting Solutions to Systems Return

  26. 7 Computing and Plotting Solutions to Systems Computing and Plotting Solutions to Systems • [t,u] = ode45(’ball’,[0,3],[0;50]); Return

  27. 7 Computing and Plotting Solutions to Systems Computing and Plotting Solutions to Systems • [t,u] = ode45(’ball’,[0,3],[0;50]); • plot(t,u) – plots all of the components versus t . Return

  28. 7 Computing and Plotting Solutions to Systems Computing and Plotting Solutions to Systems • [t,u] = ode45(’ball’,[0,3],[0;50]); • plot(t,u) – plots all of the components versus t . • plot(t,u(:,1)) – first component versus t . Return

  29. 7 Computing and Plotting Solutions to Systems Computing and Plotting Solutions to Systems • [t,u] = ode45(’ball’,[0,3],[0;50]); • plot(t,u) – plots all of the components versus t . • plot(t,u(:,1)) – first component versus t . • plot(u(:,1),u(:,2)) – second component versus the first. Return

  30. 7 Computing and Plotting Solutions to Systems Computing and Plotting Solutions to Systems • [t,u] = ode45(’ball’,[0,3],[0;50]); • plot(t,u) – plots all of the components versus t . • plot(t,u(:,1)) – first component versus t . • plot(u(:,1),u(:,2)) – second component versus the first. This is a phase plane plot. Return

  31. 7 Computing and Plotting Solutions to Systems Computing and Plotting Solutions to Systems • [t,u] = ode45(’ball’,[0,3],[0;50]); • plot(t,u) – plots all of the components versus t . • plot(t,u(:,1)) – first component versus t . • plot(u(:,1),u(:,2)) – second component versus the first. This is a phase plane plot. • plot3(u(:,1),u(:,2),t) – 3-D plot. Return

  32. 8 Solving Higher Order Equations Solving Higher Order Equations Return

  33. 8 Solving Higher Order Equations Solving Higher Order Equations • Reduce to a first order system and solve the system. Return

  34. 8 Solving Higher Order Equations Solving Higher Order Equations • Reduce to a first order system and solve the system. • Example: The motion of a pendulum is modeled by θ ′′ = − g L sin θ − Dθ ′ . Return

  35. 8 Solving Higher Order Equations Solving Higher Order Equations • Reduce to a first order system and solve the system. • Example: The motion of a pendulum is modeled by θ ′′ = − g L sin θ − Dθ ′ . • Introduce ω = θ ′ . Return

  36. 8 Solving Higher Order Equations Solving Higher Order Equations • Reduce to a first order system and solve the system. • Example: The motion of a pendulum is modeled by θ ′′ = − g L sin θ − Dθ ′ . • Introduce ω = θ ′ . Notice ω ′ = − g L sin θ − Dθ ′ . Return

  37. 9 Equivalent First Order System Equivalent First Order System Return Higher order

  38. 9 Equivalent First Order System Equivalent First Order System θ ′ = ω ω ′ = − g L sin θ − Dω Return Higher order

  39. 9 Equivalent First Order System Equivalent First Order System θ ′ = ω ω ′ = − g L sin θ − Dω • Change to vector notation. (Use M ATLAB vector notation) Return Higher order

  40. 9 Equivalent First Order System Equivalent First Order System θ ′ = ω ω ′ = − g L sin θ − Dω • Change to vector notation. (Use M ATLAB vector notation) � u(1) = θ Return Higher order

  41. 9 Equivalent First Order System Equivalent First Order System θ ′ = ω ω ′ = − g L sin θ − Dω • Change to vector notation. (Use M ATLAB vector notation) � u(1) = θ � u(2) = ω Return Higher order

  42. 10 Derivative m-file pend.m Derivative m-file pend.m function upr = pend(t,u) L= 1; global D th = u(1); om = u(2); thpr = om; ompr = -(9.8/L)*sin(th) - D*om; upr = [thpr; ompr]; Pendulum Short

Recommend


More recommend