### Solving Differential Equations using MATLAB

```EGR 272 – Solving Differential Equations using MATLAB
Solving Differential Equations using MATLAB:
Notes on using dsolve('eqn1','eqn2', ...)
• Symbolic equations:
• ‘eqn1’, ‘eqn2’ represent symbolic differential equations and initial
conditions
• Example: dsolve(‘Dy + 4y = 2’, ‘y(0) = 10’)
• Independent variable:
• The default independent variable is t, but can be changed by listing it.
• Example: dsolve(‘Dy + 4y = 2’, ‘y(0) = 10’)
% Dy means dy/dt
• Example: dsolve(‘Dy + 4y = 2’, ‘y(0) = 10’, x) % Dy means dy/dx
• Derivatives:
• Dy – 1st derivative (note: avoid using D as a symbolic variable)
• D2y – 2nd derivative, D3y = 3rd derivative, etc.
• Initial conditions:
• Examples: ‘y(0) = 2’, ‘Dy(0) = 4’, ‘D2y(0) = 6’, etc
• If fewer than N initial conditions are provided for an Nth order DE, the
solution will contain constants C1, C2, …
1
EGR 272 – Solving Differential Equations using MATLAB
Example:
Solve for y(t) in the following first-order DE if y(0) = 8
dy
 10y(t)  20, t  0
dt
MATLAB Solution:
 Answer : v(t) vn  vf  6e-10t  2 V, t  0
2
EGR 272 – Solving Differential Equations using MATLAB
Example:
Solve for y(t) in the following second-order DE if y(0) = 2 and y’(0) = -4
d2v
dv

7
 12v(t) 10e-2t , t  0
2
dt
dt
 Answer : v(t) vn  vf  - 6e-3t  3e-4t  5e-2t , t  0
MATLAB Solution:
Note: This example uses a forcing function of 10e-2t (right-side of the
equation). In EGR 270 we will only deal with DC sources, so the forcing
functions will always be constants.
3
EGR 272 – Solving Differential Equations using MATLAB
Graphing the Solution to a Differential Equation:
Since the solution to a differential equation is a symbolic equation, it can easily be
graphed using ezplot.
Example: Graph the solution to the previous example:
d2v
dv

7
 12v(t) 10e-2t , t  0
2
dt
dt
 Answer : v(t) vn  vf  - 6e-2t  3e-2t  5e-2t , t  0
Discussion: Does this graph satisfy
the initial and final values for v(t)?
4
EGR 272 – Solving Differential Equations using MATLAB
5
Class Example: A) Solve for v(t) in the following 1st - order DE if v(0) = 12
dv
 10v(t)  30, t  0
dt
B) Repeat this example using MATLAB
Graph the solution using ezplot( ) from 0 to 5
Answer : v(t)  3  9e -10t , t  0
EGR 272 – Solving Differential Equations using MATLAB
6
Class Example: A) Solve for i(t) in the following 2nd -order DE if i(0) = 6, i’(0) = 38
d 2i
di

6
 9i(t)  18, t  0
dt 2
dt
B) Repeat this example using MATLAB
Graph the solution using ezplot( ) from 0 to 5
Answer : i(t)  2  50t  4e -3t , t  0
EGR 272 – Solving Differential Equations using MATLAB
7
Significance of overdamped, critically damped, and underdamped solutions
A circuit with an overdamped response is called an overdamped circuit (similar for the
other types of damping). What does this mean about the circuit?
First, some definitions:
Damping – the act of removing oscillations
Example: A shock absorber might be adjusted so that it doesn’t oscillate, but smoothly
returns a wheel to its initial position after an impact.
Example: A switch is thrown in a circuit and an output voltage adjusts to a new level.
• In an overdamped circuit, it would reach the new level smoothly and without
oscillation (ringing).
• In an underdamped circuit, it would oscillate as it approached the new level.
• See the illustration on the following slide.
EGR 272 – Solving Differential Equations using MATLAB
8
Example: Different types of damping in an RLC circuit
For the circuit below we can easily see that v(0) = 0V and v() = 10V.
So when the switch closes at t = 0, how does v(t) get to 10V?
This is a 2nd-order circuit, so it must have a 2nd-order response. So it must be
overdamped, underdamped, or critically damped. Sketch v(t) below.
t=0
R
10 V
+
_
L
+
C
v (t)
_
v(t)
t
EGR 272 – Solving Differential Equations using MATLAB
Example:
The DE for v(t) in the circuit below if L = 100 H and C = 10 uF is:
t=0
R
10 V
+
_
L
+
C
v (t)
_
d 2 v  R  dv
    100v(t)  1000, t  0
dt 2  10  dt
i(0)  0, i' (0)  0
A) What value of R results in a critically-damped circuit?
R
The characteristic equation is s 2   s  100  0
 10 
For critical damping it should be in the form (s  10) 2  s 2  20s  100  0, so
R
 20, or R  200 for critical damping
10
B) Use MATLAB so solve the DE and graph the response for:
• R = 200 (critically damped)
• R = 350 (overdamped)
• R = 50 (underdamped)
9
EGR 272 – Solving Differential Equations using MATLAB
Example: (continued) Solve and graph
the DE for R = 350, 200, and 50 using
MATLAB.
10
```