Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Lecture 10

Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

ENE 2017

Engineering Programming
Prof. Keonwook Kim
Division of Electronics and Electrical Engineering
Dongguk University, Seoul, Korea

Ch.15 Ordinary Differential


Equations
Mathematical models in many different fields.
Experiments with MATALB – Cleve Moler

Ordinary differential equations


• Differential equations are relations between unknown
functions and their derivatives.
• Computing numerical solutions to differential equations is
one of the most important tasks in technical computing, and
one of the strengths of MATLAB.
• We are interested in situations where the functions are not
known and cannot be represented by simple formulas.
• We will compute numerical approximations to the values of a
function at enough points to print a table or plot a graph.

Experiments with MATALB – Cleve Moler

Ordinary differential equations


• Imagine you are traveling on a mountain road.
• Your altitude varies as you travel. The altitude can be regarded as a
function of the distance you have traveled.
• Let x denote the distance traveled and y = y(x) denote the altitude.
• Carrying an altimeter with you to plot a graph of altitude versus
distance.
• A sign saying that you are on a 6% uphill grade.
• Value of x near the sign, and for h = 100

• You could plot a graph of dy/dx, even


though you do not have closed-form formulas
Experiments with MATALB – Cleve Moler

Ordinary differential equations


• Orbit around a central star.
• Program needed to compute circular and elliptical orbits.
• Floating-point arithmetic was so slow. 1
0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
-1 -0.5 0 0.5 1

Experiments with MATALB – Cleve Moler

Ordinary differential equations


• The orbit is actually an ellipse that deviates from an exact
circle by about 7%.
• The output produced with h = 1/32 and n = 201 is shown. The
green orbit is another ellipse that deviates from an exact circle by
less than 1%.
1

0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
-1 -0.5 0 0.5 1
Experiments with MATALB – Cleve Moler

Ordinary differential equations


• Looking for two functions with the property.
• The derivative of the first function is equal to the second and
• The derivative of the second function is equal to the negative of the
first.

Experiments with MATALB – Cleve Moler

Ordinary differential equations


• Mathematical models involving systems of ordinary
differential equations have one independent variable and one
or more dependent variables.
• All the dependent variables into a single vector y as the state of the
system.
• MATLAB a system of odes takes the form.
• Scalar independent variable, t, and the vector of dependent variables,
y.
Experiments with MATALB – Cleve Moler

Ordinary differential equations


• The MATLAB suite of ode solvers includes
• ode23, ode45, ode113, ode23s, ode15s, ode23t, and ode23tb.
• The digits in the names refer to the order of the underlying
algorithms.
• All of the functions automatically determine the step size required to
obtain a prescribed accuracy.
• For example ode23 compares a second order method with a third order
method to estimate the step size.

Experiments with MATALB – Cleve Moler

Ordinary differential equations


• All of the functions in the ode suite take at least three input
arguments.
• F, the function defining the differential equations,
• tspan, the vector specifying the integration interval,
• y0, the vector of initial conditions. 1

0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1
0 1 2 3 4 5 6 7
Experiments with MATALB – Cleve Moler

Ordinary differential equations


1

0.8

0.6

0.4

0.2

-0.2

-0.4

-0.6

-0.8

-1

-1 -0.5 0 0.5 1

Experiments with MATALB – Cleve Moler

Ordinary differential equations


• “@” symbol is known as an anonymous function because it
does not have a name until it is assigned to acircle.
Experiments with MATALB – Cleve Moler

Ordinary differential equations


• One elementary first order algorithm
function [t,y] = ode1(F,tspan,y0)
t0 = tspan(1);
tfinal = tspan(end);
h = (tfinal ‐ t0)/200;
y = y0;
figure, plot(y(2),y(1),'o'), axis equal,hold on;
for t = t0:h:tfinal
ydot = F(t,y);
y = y + h*ydot
plot(y(2),y(1),'o');
end
hold off

You might also like