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 Matlab Solvers M ATLAB has several solvers. • ode45 � This is the first choice. Return
2 Matlab Solvers Matlab Solvers M ATLAB has several solvers. • ode45 � This is the first choice. • ode23 Return
2 Matlab Solvers Matlab Solvers M ATLAB has several solvers. • ode45 � This is the first choice. • ode23 � This is a good second choice. Return
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
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
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
3 ode45 ode45 Return Solvers
3 ode45 ode45 • Uses variable step size. Return Solvers
3 ode45 ode45 • Uses variable step size. � Specify error tolerance instead of step size. Return Solvers
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
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
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
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
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
4 Solving Systems Solving Systems Return
4 Solving Systems Solving Systems • Example: x ′ = v v ′ = − 9 . 8 − 0 . 04 v | v | Return
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
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
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
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
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
7 Computing and Plotting Solutions to Systems Computing and Plotting Solutions to Systems Return
7 Computing and Plotting Solutions to Systems Computing and Plotting Solutions to Systems • [t,u] = ode45(’ball’,[0,3],[0;50]); Return
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
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
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
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
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
8 Solving Higher Order Equations Solving Higher Order Equations Return
8 Solving Higher Order Equations Solving Higher Order Equations • Reduce to a first order system and solve the system. Return
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
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
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
9 Equivalent First Order System Equivalent First Order System Return Higher order
9 Equivalent First Order System Equivalent First Order System θ ′ = ω ω ′ = − g L sin θ − Dω Return Higher order
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
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
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
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