0% found this document useful (0 votes)
9 views8 pages

Ode Basis

The document provides a guide on selecting appropriate ODE solvers in MATLAB, detailing various solvers like ode45, ode23, and ode15s along with their problem types, accuracy, and when to use them. It also explains the concept of stiffness in ordinary differential equations and includes examples of how to implement these solvers for different systems, such as pendulums and spring-mass systems. Additionally, it emphasizes the importance of defining initial conditions and using options for solver settings.

Uploaded by

jp76kh9c4f
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views8 pages

Ode Basis

The document provides a guide on selecting appropriate ODE solvers in MATLAB, detailing various solvers like ode45, ode23, and ode15s along with their problem types, accuracy, and when to use them. It also explains the concept of stiffness in ordinary differential equations and includes examples of how to implement these solvers for different systems, such as pendulums and spring-mass systems. Additionally, it emphasizes the importance of defining initial conditions and using options for solver settings.

Uploaded by

jp76kh9c4f
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

ODE Basis

Ordinary Differential Equations >


Chose an ODE solver
Solver Problem Type Accuracy When to Use

ode45 Medium Most of the <me. ode45 should be the first solver you try.

ode23 can be more efficient than ode45 at problems with


ode23 Nons<ff Low crude tolerances, or in the presence of moderate s<ffness.
ode113 can be more efficient than ode45 at problems with
ode113 Low to High stringent error tolerances, or when the ODE func<on is
expensive to evaluate.
Try ode15s when ode45 fails or is inefficient and you
ode15s Low to Medium suspect that the problem is s<ff. Also use ode15s when
solving differen<al algebraic equa<ons (DAEs).
del
lucro

ode23s can be more efficient than ode15s at problems with


crude error tolerances. It can solve some s<ff problems for
which ode15s is not effec<ve.
e/o

ode23s Low ode23s computes the Jacobian in each step, so it is


S<ff beneficial to provide the Jacobian via odeset to maximize
efficiency and accuracy.
If there is a mass matrix, it must be constant.
scopo

Use ode23t if the problem is only moderately s<ff and you


la

ode23t Low need a solu<on without numerical damping.


ode23t can solve differen<al algebraic equa<ons (DAEs).
Like ode23s, the ode23tb solver might be more efficient
ode23tb Low
per

than ode15s at problems with crude error tolerances.


Use ode15i for fully implicit problems f(t,y,y’) = 0 and for
ode15i Fully implicit Low differen<al algebraic equa<ons (DAEs) of index 1.

An ordinary differential equation problem is stiff if the solution being sought varies slowly,
but there are nearby solutions that vary rapidly, so the numerical method must take small
.
steps to obtain satisfactory results.
Ordinary Differential Equations >
Chose an ODE solver
Solver Problem Type Accuracy When to Use

ode45 Medium Most of the <me. ode45 should be the first solver you try.

ode23 can be more efficient than ode45 at problems with


ode23 Nons<ff Low crude tolerances, or in the presence of moderate s<ffness.
ode113 can be more efficient than ode45 at problems with
ode113 Low to High stringent error tolerances, or when the ODE func<on is
expensive to evaluate.
Try ode15s when ode45 fails or is inefficient and you
ode15s Low to Medium suspect that the problem is s<ff. Also use ode15s when
solving differen<al algebraic equa<ons (DAEs).
del
lucro

ode23s can be more efficient than ode15s at problems with


crude error tolerances. It can solve some s<ff problems for
which ode15s is not effec<ve.
e/o

ode23s Low ode23s computes the Jacobian in each step, so it is


S<ff beneficial to provide the Jacobian via odeset to maximize
efficiency and accuracy.
If there is a mass matrix, it must be constant.
scopo

Use ode23t if the problem is only moderately s<ff and you


la

ode23t Low need a solu<on without numerical damping.


ode23t can solve differen<al algebraic equa<ons (DAEs).
Like ode23s, the ode23tb solver might be more efficient
ode23tb Low
per

than ode15s at problems with crude error tolerances.


Use ode15i for fully implicit problems f(t,y,y’) = 0 and for
ode15i Fully implicit Low differen<al algebraic equa<ons (DAEs) of index 1.

..Generally stiffness can be described as having time constants


Nonstiff Vs Stiff
in a model that vary by several orders of magnitude..
Use Matlab to solve ODE

the function depends from ’t’ and ‘y’

[t,y] = ode45(@(t,y) -2*y,[0 5],2,odeopt);

options
function
initial condition

time span

cut and paste in Matlab

odeopt = odeset ('RelTol', 0.00001, 'AbsTol', 0.00001,'InitialStep',0.5,'MaxStep',0.5);


[t,y] = ode45(@(t,y) -2*y,[0 5],2,odeopt);
plot(t,y)
⎛ g⎞
Use Matlab to solve ODE θ!! + ⎜ ⎟ senθ = 0
⎝ L⎠
⎛ g⎞
How to integrate pendulum equation, θ!! + ⎜ ⎟ θ = 0
⎝ L⎠

d 2θ g g
+ (θ ) = ω 2
=
E’ vietato ogni utilizzo diverso da quello inerente la preparazione dell’esame del corso di Meccanica delle Vibrazioni @Units

sin 0 isolates the term with the highest derivative, with


dt 2 L l

d 2θ
2
= −ω 2 sin (θ )
dt

θ = y1
E’ espressamente vietato l’utilizzo per qualsiasi scopo commerciale e/o di lucro

Variable substitution is performed


dθ dy1 d 2θ d 2 y1 dy2
= = y2 = 2 =
dt dt dt 2 dt dt

The equation of order 2 dy1


is rewritten with two equations
dt
= y2
of order 1
dy2
dt
= − ω 2sin(y1)
Use Matlab to solve ODE

we define a function for these two differential equations


dy1
= y2 dy _ dt = @(t, y)[y2 ;
E’ vietato ogni utilizzo diverso da quello inerente la preparazione dell’esame del corso di Meccanica delle Vibrazioni @Units

dt
−ω 2 sin(y1 )];
dy2
dt
= − ω 2sin(y1)

[t, y] = ode45(dy _ dt,[0 25],[0.0 1.0],odeopt);


E’ espressamente vietato l’utilizzo per qualsiasi scopo commerciale e/o di lucro

options
function
initial conditions (2, for y1 and for y2)
time span

y is a vector and contains y1 and y2


Use Matlab to solve ODE
The same structure and procedure applies to different systems:

undamped spring
mass system dy1
= y2
E’ vietato ogni utilizzo diverso da quello inerente la preparazione dell’esame del corso di Meccanica delle Vibrazioni @Units

d2x k dt
+ x=0
dt 2 m dy2 k
dt
=− y
m 1
damped spring mass
dy1
system
= y2
E’ espressamente vietato l’utilizzo per qualsiasi scopo commerciale e/o di lucro

d 2 x c dx k dt
+ + x=0 dy2 c k
dt 2 m dt m
dt
=− y
m 2
− y
m 1

forced damped dy1


spring mass system
dt
= y2
2
d x c dx k Fo
+ + x = sin (ω t ) dy2 c k F0
dt 2 m dt m m dt
=− y
m 2
− y
m 1
+ m
sin(ωt)
undamped
spring mass system dy _ dt = @(t, y)[y2 ;
k
− y1 ];
m
E’ vietato ogni utilizzo diverso da quello inerente la preparazione dell’esame del corso di Meccanica delle Vibrazioni @Units

forced damped dy _ dt = @(t, y)[y2 ;


spring mass system c k
− y2 − y1 ];
E’ espressamente vietato l’utilizzo per qualsiasi scopo commerciale e/o di lucro

m m

forced damped dy _ dt = @(t, y)[y2 ;


spring mass system c k F
− y2 − y1 + o sin (ω t )];
m m m

You might also like