100% found this document useful (1 vote)
101 views3 pages

Higher Order ODEs PDF

This document discusses using MATLAB to solve higher order differential equations by converting them into systems of first order equations. As an example, a second order differential equation with constant coefficients is converted into two first order equations by defining new variables for the highest derivative and the original dependent variable. The system can then be solved numerically using MATLAB ODE solvers. Code is provided to solve the example equation numerically and compare the solution to the exact analytical solution.

Uploaded by

kirti
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
100% found this document useful (1 vote)
101 views3 pages

Higher Order ODEs PDF

This document discusses using MATLAB to solve higher order differential equations by converting them into systems of first order equations. As an example, a second order differential equation with constant coefficients is converted into two first order equations by defining new variables for the highest derivative and the original dependent variable. The system can then be solved numerically using MATLAB ODE solvers. Code is provided to solve the example equation numerically and compare the solution to the exact analytical solution.

Uploaded by

kirti
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/ 3

MATLAB Solution of Higher Order Differential Equations

To use MATLAB ODE solvers for equations of orders higher than 1, we must first
write the equation as a system of first order equations. This is easily done as
demonstrated in the following example.
Second Order Example
Consider the following well-known 2nd order ODE with constant coefficients a,b,c
and forcing function f(t)

d2y
dy

b
cy f (t )
dt
dt 2

The general approach is to solve for the highest derivative

d2y 1
dy

f (t ) b cy
2
dt
a
dt

Next define two new variables x1 y and x2 y and so this allows us to write
the original ODE as the two equations

dx1
x2
dt
dx2 1
f (t ) bx2 cx1
dt
a
or in matrix form

x2

x1

x 1 f (t ) bx cx
2
1
2 a

This is now a first order matrix ODE and the form is sometimes called the Cauchy
or state variable form. Note that this same scheme can be used for ODEs with
orders higher than two.

To use any of the MATLAB ODE solvers we simply follow the previous coding but
apply it to the array of ODEs.
Consider the specific case with a = c = 1, b = f(t) = 0. This yields the equation

d2y
y0
dt 2
that we have seen before. Recall that the exact solution was given by

y A sin t B cos t , where the constants are A x2 (0), B x1 (0) . We will


choose the specific initial conditions x1 (0) y(0) 5 and x2 (0) y (0) 5
Following the usual coding from the first order examples, the MATLAB code that
will solve this second order example is listed below. The code simply handles the
problem in a matrix format and plots both the numerical and exact analytical
solutions.

% MCE 372 Engineering Analysis Example Code


% Solution of Second Order ODE d2y/dt2+y = 0
% Exact Analytical Solution: y=xo(2)*sint+xo(1)*cost
function main
clc;clear all;clf
% Enter initial condition matrix
xo=[5,5];
[t,x]=ode45(@DE2,[0:0.1:10],xo);
plot(t,x(:,1),'k-','Linewidth',1.5)
xlabel('t'),ylabel('y'),grid on
title('Numerical Solution of d^2y/dt^2+y=0 , y(0)=5, dot(0)=5')
hold on
% Plot Exact Solution
T=0:0.5:10;Y=xo(2)*sin(T)+xo(1)*cos(T);
plot(T,Y,'or','markerfacecolor','r')
legend('Numerical Solution','Exact Solution')
function dxdt=DE2(t,x)
% Computes Derivatives of Each Equation
dxdt=[x(2);-x(1)];

The solution plots are given by

Numerical Solution of d2y/dt 2+y=0 , y(0)=5, ydot(0)=5


8
6
4

2
0
-2
-4
Numerical Solution
Exact Solution

-6
-8

5
t

10

You might also like