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

math 211 math 211
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

1

Math 211 Math 211

Lecture #14 MATLAB’s ODE Solvers September 26, 2003

slide-2
SLIDE 2

Return

2

Matlab Solvers Matlab Solvers

MATLAB has several solvers.

slide-3
SLIDE 3

Return

2

Matlab Solvers Matlab Solvers

MATLAB has several solvers.

  • ode45
slide-4
SLIDE 4

Return

2

Matlab Solvers Matlab Solvers

MATLAB has several solvers.

  • ode45

This is the first choice.

slide-5
SLIDE 5

Return

2

Matlab Solvers Matlab Solvers

MATLAB has several solvers.

  • ode45

This is the first choice.

  • ode23
slide-6
SLIDE 6

Return

2

Matlab Solvers Matlab Solvers

MATLAB has several solvers.

  • ode45

This is the first choice.

  • ode23

This is a good second choice.

slide-7
SLIDE 7

Return

2

Matlab Solvers Matlab Solvers

MATLAB 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.

slide-8
SLIDE 8

Return

2

Matlab Solvers Matlab Solvers

MATLAB 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.

  • de15s
slide-9
SLIDE 9

Return

2

Matlab Solvers Matlab Solvers

MATLAB 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.

  • de15s
  • All use the same syntax.
slide-10
SLIDE 10

Return Solvers

3

  • de45
  • de45
slide-11
SLIDE 11

Return Solvers

3

  • de45
  • de45
  • Uses variable step size.
slide-12
SLIDE 12

Return Solvers

3

  • de45
  • de45
  • Uses variable step size.

Specify error tolerance instead of step size.

slide-13
SLIDE 13

Return Solvers

3

  • de45
  • de45
  • Uses variable step size.

Specify error tolerance instead of step size. MATLAB chooses the step size at each step to achieve

the limit on the error.

slide-14
SLIDE 14

Return Solvers

3

  • de45
  • de45
  • Uses variable step size.

Specify error tolerance instead of step size. MATLAB chooses the step size at each step to achieve

the limit on the error.

The default tolerance is good enough for this course.

slide-15
SLIDE 15

Return Solvers

3

  • de45
  • de45
  • Uses variable step size.

Specify error tolerance instead of step size. MATLAB chooses the step size at each step to achieve

the limit on the error.

The default tolerance is good enough for this course.

  • Syntax
slide-16
SLIDE 16

Return Solvers

3

  • de45
  • de45
  • Uses variable step size.

Specify error tolerance instead of step size. MATLAB 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,[t0, tf], y0);

slide-17
SLIDE 17

Return Solvers

3

  • de45
  • de45
  • Uses variable step size.

Specify error tolerance instead of step size. MATLAB 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,[t0, tf], y0); plot(t,y)

slide-18
SLIDE 18

Return

4

Solving Systems Solving Systems

slide-19
SLIDE 19

Return

4

Solving Systems Solving Systems

  • Example:

x′ = v v′ = −9.8 − 0.04v|v|

slide-20
SLIDE 20

Return

4

Solving Systems Solving Systems

  • Example:

x′ = v v′ = −9.8 − 0.04v|v|

  • Change to vector notation. (Use MATLAB vector notation)
slide-21
SLIDE 21

Return

4

Solving Systems Solving Systems

  • Example:

x′ = v v′ = −9.8 − 0.04v|v|

  • Change to vector notation. (Use MATLAB vector notation)

u(1)

= x

slide-22
SLIDE 22

Return

4

Solving Systems Solving Systems

  • Example:

x′ = v v′ = −9.8 − 0.04v|v|

  • Change to vector notation. (Use MATLAB vector notation)

u(1)

= x

u(2)

= v

slide-23
SLIDE 23

Return System

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];

slide-24
SLIDE 24

Return System ball.m

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

slide-25
SLIDE 25

Return

7

Computing and Plotting Solutions to Systems Computing and Plotting Solutions to Systems

slide-26
SLIDE 26

Return

7

Computing and Plotting Solutions to Systems Computing and Plotting Solutions to Systems

  • [t,u] = ode45(’ball’,[0,3],[0;50]);
slide-27
SLIDE 27

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.
slide-28
SLIDE 28

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.
slide-29
SLIDE 29

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.

slide-30
SLIDE 30

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.
slide-31
SLIDE 31

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.
slide-32
SLIDE 32

Return

8

Solving Higher Order Equations Solving Higher Order Equations

slide-33
SLIDE 33

Return

8

Solving Higher Order Equations Solving Higher Order Equations

  • Reduce to a first order system and solve the system.
slide-34
SLIDE 34

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θ′.

slide-35
SLIDE 35

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 ω = θ′.
slide-36
SLIDE 36

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θ′.

slide-37
SLIDE 37

Return Higher order

9

Equivalent First Order System Equivalent First Order System

slide-38
SLIDE 38

Return Higher order

9

Equivalent First Order System Equivalent First Order System

θ′ = ω ω′ = − g L sin θ − Dω

slide-39
SLIDE 39

Return Higher order

9

Equivalent First Order System Equivalent First Order System

θ′ = ω ω′ = − g L sin θ − Dω

  • Change to vector notation. (Use MATLAB vector notation)
slide-40
SLIDE 40

Return Higher order

9

Equivalent First Order System Equivalent First Order System

θ′ = ω ω′ = − g L sin θ − Dω

  • Change to vector notation. (Use MATLAB vector notation)

u(1)

= θ

slide-41
SLIDE 41

Return Higher order

9

Equivalent First Order System Equivalent First Order System

θ′ = ω ω′ = − g L sin θ − Dω

  • Change to vector notation. (Use MATLAB vector notation)

u(1)

= θ

u(2)

= ω

slide-42
SLIDE 42

Pendulum Short

10

Derivative m-file pend.m Derivative m-file pend.m

function upr = pend(t,u) L= 1; global D th = u(1);

  • m = u(2);

thpr = om;

  • mpr = -(9.8/L)*sin(th) - D*om;

upr = [thpr; ompr];