Professional Documents
Culture Documents
Aboozar Ghaffari
Ghafari@ieee.org
x = f (t,x).
To solve this equation we must find a function x(t) such that
x(t) = f (t, x(t )), for all t .
This means that at every point (t, x(t)) on the graph of x, the graph must have
slope equal to f (t,x(t)).
We can turn this interpretation around to give a geometric view of what
a differential equation is, and what it means to solve the equation.
Imagine, if you can, a small line segment attached to each point (t, x)
with slope f (t,x).
This collection of lines is called a direction line field, and it provides the
geometric interpretation of a differential equation.
To find a solution we must find a curve in the plane which is tangent at
each point to the direction line at that point.
Ghafari@ieee.org
Ghafari@ieee.org
Ghafari@ieee.org
Ghafari@ieee.org
Eulers Method
We want to find an approximate solution to the initial value
Ghafari@ieee.org
y = y + t, y(0) = 1 (5.2)
on the interval [0, 3] .
Note that the differential equation in (5.2) is in normal form
y = f (t,y), where f (t,y) = y + t .
Before invoking the eul routine, you must first write a
function M-file
function yprime = yplust(t,y)
yprime = y + t;
Ghafari@ieee.org
>> yplust(1,2)
ans = 3
Now that your function M-file is operational, its time to invoke
the eul routine. The general syntax is
[t,y]=eul(@yplust,tspan,y0,stepsize)
where yplust is the name of the function M-file, tspan is the vector
[t0,tfinal] containing the initial and final time conditions, y0 is the
y-value of the initial condition, and stepsize is the step size to be
used in Eulers method.
Actually, the step size is an optional parameter. If you enter this
program will choose a default step size equal to (tfinal-t0)/100.
[t,y]=eul(@yplust,tspan,y0)
Ghafari@ieee.org
Ghafari@ieee.org
Ghafari@ieee.org
Ghafari@ieee.org
Ghafari@ieee.org
value problem y = f (t,y), with y(a) = y0, on the interval [a, b].
As before, we set t0 = a, choose a step size h, and then inductively
define
s1 = f (tk, yk),
s2 = f (tk + h, yk + hs1),
yk+1 = yk + h(s1 + s2)/2,
tk+1 = tk + h,
for k = 0, 1, 2, . . . , N, where N is large enough so that tN b.
This algorithm is available in the M-file rk2.m, which is listed in
the appendix of this chapter.
Ghafari@ieee.org
The syntax for using rk2 is exactly the same as the syntax
Ghafari@ieee.org
Ghafari@ieee.org
Introduction to PPLANE7
A planar system is a system of differential equations of the form
x =f (t, x, y),
y =g(t, x, y). (7.1)
The variable t in system (7.1) usually represents time and is called
the independent variable.
Frequently, the right-hand sides of the differential equations do
not explicitly involve the variable t , and can be written in the
form
x = f (x, y),
y = g(x, y). (7.2)
Such a system is called autonomous.
Ghafari@ieee.org
becomes
x = F(t, x).
Ghafari@ieee.org
Ghafari@ieee.org
MATLAB.
The suite now contains the seven solvers ode23, ode45,
ode113, ode15s, ode23s, ode23t, and ode23tb.
We will spend most of our time discussing the general
purpose solver ode45. We will also briefly discuss ode15s, an
excellent solver for stiff systems.
Although we will not discuss the other solvers, it is
important to realize that the calling syntax is the same for
each solver in MATLABs suite.
Ghafari@ieee.org
Ghafari@ieee.org
(8.3)
Ghafari@ieee.org
equations.
Consider the following system of n first order differential equations:
x1 = f1(t, x1, x2, . . . , xn),
x2 = f2(t, x1, x2, . . . , xn),
...
xn = fn(t, x1, x2, . . . , xn).
Ghafari@ieee.org
Finally, if we define F(t, x) = [f1(t, x), f2(t, x), . . . , fn(t, x)]T , then
on the interval [0, 10], with initial conditions x1(0) = 0 and x2(0) = 1.
We can write system (8.9) as the vector equation
Ghafari@ieee.org
Ghafari@ieee.org
Recall that the initial conditions for system (8.9) were given as
x1(0) = 0 and x2(0) = 1. Consequently, our initial condition vector will
be
Ghafari@ieee.org
>> plot(x(:,1),x(:,2))
>> title('x_1'' = x_2-x_1^2 and x_2'' = -x_1-2x_1x_2')
>> xlabel('x_1'), ylabel('x_2'), grid
Ghafari@ieee.org
Ghafari@ieee.org
Example 4
Plot the solution of the initial value problem
Ghafari@ieee.org
Ghafari@ieee.org
Introduction to ODESOLVE
The MATLAB function odesolve1 provides a way to use
Ghafari@ieee.org
Starting odesolve
The interface of odesolve is very similar to those found in
Ghafari@ieee.org
If we introduce the velocities u = x and v = y, the system in (9.1) is equivalent to the first order
system
x = u,
u = (k2(y x) k1x)/m1,
y = v,
v = ( k2(y x) + f (t))/m2.
Ghafari@ieee.org
Ghafari@ieee.org
Ghafari@ieee.org
differential equation
Ghafari@ieee.org
Ghafari@ieee.org
If a single variable is used to gather the output, then the Symbolic Toolbox returns a MATLAB structure5.
A structure is an object which has user defined fields, each of which is a MATLAB object. In this case the fields are symbolic objects
containing the components of the solution6 of system (10.5). Thus the command
>> S = dsolve('Dx = -2*x - 3*y,Dy = 3*x-2*y', 'x(0) = 1,y(0) = -1','t')
S=
x: [1x1 sym]
y: [1x1 sym]
It is also possible to output the components of the solution directly with the command
>> [x,y] = dsolve('Dx = -2*x-3*y,Dy = 3*x-2*y','x(0) = 1, y(0) = -1','t')
x=
exp(-2*t)*(cos(3*t)+sin(3*t))
y=
exp(-2*t)*(sin(3*t)-cos(3*t))
Ghafari@ieee.org
Each component of the solution can be plotted versus t with the following sequence of commands.
>> ezplot(x,[0,2*pi])
>> hold on
>> ezplot(y,[0,2*pi])
>> legend('x','y')
>> hold off
Adjust the view with the axis command, and add a title and axis labels.
>> axis([0,2*pi,-1.2,1.2])
>> title('Solutions of x'' = -2x-3y, y'' = 3x-2y, x(0) = 1, y(0) = -1.')
>> xlabel('Time t')
>> ylabel('x and y')
This should produce an image similar to that in Figure 10.3. We used the Property Editor to make
one of the curves dashed.
It is also possible to produce a phase-plane plot of the solution. With the structure output the basic
command is simply ezplot(S.x,S.y). After some editing we get Figure 10.4
Ghafari@ieee.org
Ghafari@ieee.org
Ghafari@ieee.org