Вы находитесь на странице: 1из 20

1

L.D.COLLEGE OF ENGINEERING

Matlab
(FOR SOLUTION OF DIFFERENTIAL EQUATION)

M.E SEM-I (C.A.P.D.) CHEMICAL ENGG.

Guided by Prepared by
Prof. H.N.Pandya Maulik J. Patel-160280716012
Shyamesha A. Patel-160280716014
Differential Equations with 2

MATLAB
 MATLAB has some powerful features for solving
differential equations of all types. We will explore
some of these features for the Constant
Coefficient Linear Ordinary Differential Equation
forms.
 The approach here will be that of the Symbolic
Math Toolbox. The result will be the form of the
function and it may be readily plotted with
MATLAB.
Symbolic Differential 3

Equation
y Termsy

dy Dy
dt
2
d y
2 D2y
dt
n
d y
n Dny
dt
Finding Solutions to 4

Differential Equations
 Solving a First Order Differential Equation
 Solving a Second Order Differential
Equation
 Solving Simultaneous Differential
Equations
 Solving Nonlinear Differential Equations
 Numerical Solution of a Differential
Equation
Solving a 1 st Order DE 5

 The Matlab command used to solve differential


equations is dsolve .

dy
 Consider the differential  2 y  12
equation: dt

 The general solution is given by:

 Verify the solution using dsolve command


Solving a Differential 6

Equation in Matlab
» syms y t

» ys=dsolve('Dy+2*y=12')

ys =6+exp(-2*t)*C1

 C1 is a constant which is specified by way of the


initial condition

 Dy means dy/dt and D2y means d2y/dt2 etc


Verify Results 7

 Verify results given y(0) = 9

y(0)  9  C1  3

» ys=dsolve('Dy+2*y=12','y(0)=9')

ys =
6+3*exp(-2*t)
Solving a 2 nd Order DE 8

Find the general solution of: d2y 2


c y  0

2
dt

» syms c y
» ys=dsolve('D2y = - c^2*y')

ys = C1*sin(c*t)+C2*cos (c*t)

y(t )  C1 sin( ct )  C2 cos(ct )


8
9
Solving Simultaneous
Differential Equations Example
 Syntax for solving simultaneous differential equations is:
dsolve('equ1', 'equ2',…)

 Solve the following set of differential equations:

dx dy
 3x  4 y  4 x  3 y
dt dt
9
10
General Solution
 Given the equations:

dx dy
 3x  4 y  4 x  3 y
dt dt

 The general solution is given by:

x(t )  c1e3t cos(4t )  c2e3t sin( 4t )


y(t )  c1e sin( 4t )  c2e cos(4t )
3t 3t
11
Matlab Verification
 Given the dx dy
equations:  3x  4 y  4 x  3 y
dt dt

 General x(t )  c1e3t cos(4t )  c2e3t sin( 4t )


solution is:
y(t )  c1e sin( 4t )  c2e cos(4t )
3t 3t

» syms x y t
» [x,y]=dsolve('Dx=3*x+4*y','Dy=-4*x+3*y')
x = exp(3*t)*(cos(4*t)*C1+sin(4*t)*C2)
y = -exp(3*t)*(sin(4*t)*C1-cos(4*t)*C2)
12
Initial Conditions
 Solve the previous system with the initial conditions:

x ( 0)  0 y ( 0)  1

» [x,y]=dsolve('Dx=3*x+4*y','Dy=-4*x+3*y',
'y(0)=1','x(0)=0')

x = exp(3*t)*sin(4*t) x  e sin( 4t )
3t

y = exp(3*t)*cos(4*t) y  e cos(4t )
3t
Non-Linear Differential Equation 13
Example

 Solve the differential equation: dy  4  y 2


dt
Subject to initial condition:
y ( 0)  1

» syms y t
» y=dsolve('Dy=4-y^2','y(0)=1')
» y=simplify(y)
y=
y(t ) 
 
2 3e 4t  1
2*(3*exp(4*t)-1)/(1+3*exp(4*t))
1  3e 4t
Specifying the Independent 14

Parameter of a Differential Equation


 If another independent variable, other than t, is used, it
must be introduced in the dsolve command

dy
 Solve the differential equation:  2 y  12
dx
» y=dsolve('Dy+2*y=12','x')

y = 6+exp(-2*x)*C1 y( x)  6  C1e 2 x
15
Numerical Solution Example
 Not all non-linear differential equations have a closed
form solution, but a numerical solution can be found

2
d y
 Solve the differential equation:
2
 9 sin( y)  0
dt

y ( 0)  1
 Subject to initial conditions:

y (0)  0
16
Rewrite Differential Equation
2
d y d 2 y 
2
 9 sin( y)  0 2
 y  9 sin( y )
dt dt
 Rewrite in the
x1  y  
following form x2  y  x1
 
x1 (0)  y(0)  1
x2  y  9 sin( y )


x2  9 sin( x1 ) x2 (0)  y(0)  0
16
Solve DE with MATLAB 17

2
d y dy
2
 3  2 y  24
dt dt
y (0)  10 y '(0)  0

>> y = dsolve ('D2y + 3*Dy + 2*y = 24',

'y(0)=10', 'Dy(0)=0')
y = 12+2*exp(-2*t)-4*exp(-t)
>> ezplot(y, [0 6])

17
18
Reference 19

 http://www.mathworks.in/help/symbolic/simplify.h
tml

 https://www.google.co.in/#q=laplace+transform
+using+matlab
20

Thank You

Вам также может понравиться