Module 3 Part 1
Module 3 Part 1
• Use “ode23” function to solve the Differential Equation (DE) in MATLAB with end result in array
form.
Loadable Function is: [t, y] = ode23 (fcn, t, xo)
Eg: [t,y] = ode23(@cf2orderode23,[0 20],[-1;1])
• These functions (ode23) use the appropriate numerical method algorithms
The solution is returned in the matrix y, with each row values are the solutions to the DE corresponding
to each of the time instants that are defined as elements of the vector t. The value of first element of t
should be the initial time to and the solution correspond to this initial time is the initial state of the system
represented as column vector xo, and is supplied as arguments in ‘ode23’ functions so that the first row of
the output y is xo. The ‘n’ column elements of the output matrix y, are the ‘n’ linearly independent
system variables (solutions to DE) (output and successive derivatives (n-1 times) of the output variable,
where ‘n’ is the order of the system) values at the corresponding instant of time.
In the right-hand side of the loadable function, the first argument is ‘ode23’, which calls fcn, which is a
string, inline, or function handle to compute the ‘n’ set of first order DE. The function definition must
created separately of the form: ydot = fcn(t, y);
Here, the ‘n’ set of first order DE should be entered inside this created function file with a name ‘fcn’,
and ydot and y are vectors of size equal to the order of the system ‘n’.
Finding Zero –Input Response:
Ex: Given the differential equation, (D2+4D+3) y(t) = (3D+5) x(t) and with initial conditions :
y(0) = -3 ; dy(0)/dt = -6. A nth order DE can be written in ‘n’ first order DEs as (in this case n = 2):
Let y1 = y ; and y2 = Dy(t) ; implies Dy1(t) = y2(t) ---- (1) and substituting these in the given
above differential equation, we get Dy2(t) = ̶ 4y2(t) – 3y1(t) +3D x(t) + 5 x(t) ---- (2a)
Since x(t) = 0 (for ZIR), the Eqn. 2a modifies as Dy2(t) = ̶ 4y2(t) – 3y1(t) ---- (2)
These equations (1) and (2) should be defined separately in the script file as the function file “fn1.m” as :
function ydot = fn1(t, y) <------ First line of the created function file with name ‘fn1.m’
ydot = zeros (2,1); <---- creating null column matrix ydot for entry of ‘n’ first order DEs
ydot(1) = y(2); <---- entry of first DE
ydot(2) = -4*y(2) -3*y(1); <---- entry of second DE
end
While creating the function file, the first statement should start with the function command and the
right-hand side of the equal sign of this statement should start with same name as the name given to the
respective function file.
Once the function file ‘fn1.m’ is created with DEs entry in it, the solution (integration) for these DEs
can be obtained by calling this function through ‘ode23’ separately, with initial conditions defined in
MATLAB workspace as:
>> y0 = [-3;-6]; <---- initial condition vector
1|Page
>> t = linspace (0, 10, 100); <---- time duration for the solution
>> [t,y] = ode23(@fn1, t,y0); <---- calling the function for solution
The solution thus calculated in matrix form y is sketched using plot command as:
>> plot(t,y(:,1),t,y(:,2)); <--- sketch of two linearly independent solutions
y(:,1) represents y1 the output variable (one of the solution to DE) and y(:,2) represents y2 the derivative
of the output variable (2nd independent variable of the solution to DE).
Finding Impulse Response:
For the same above example, evaluate the created new set of initial conditions due to the application of
impulse at t= 0, as h(0+) = k1 and Dh(0+) = k2. Compute the values of k1 & k2 manually using method 1.
Here, h(0+) = 3 and Dh(0+) = -7 after hand calculation. Use this as the initial conditions and use
MATLAB to solve the differential equation as explained above for ZIR.
Finding Zero – State Response:
METHOD 1: Using directly the differential equation
Here only forcing function x(t) is considered and treat the initial conditions to be zero and proceed as
explained above in the total response.
METHOD 2 : Using Impulse Response of the differential equation – by convolution method
Convolution of two signals : (using Graphical Method)
Convolve the two signals h(t) = (e-3t + e-t)u(t)and x(t) = (e-ξt)u(t) for different ξ= 1,2,3,15,.001,0.1
MATLAB code:
x=inline('(exp(-ξ*t)).*(t>=0)','t')
h=inline('(exp(-t).*(t>=0))+(exp(-3*t).*(t>=0))','t')
dtau = .005; %defines an incremental value for the convolution
tau= -1:dtau:4; %defines the integrating ranges for the convolution
%lower limit value of tau (-1): depend on causality of x(t) OR may be same as tvec
%upper limit value of tau (4): depend on causality of h(t) OR everlasting nature. If a signal starts with a
non-zero value at -n, the value chosen depends on the value chosen for the upper value of tvec that
is at least tvec+n.
ti= 0; %initialising the index counter, i.e. pointer to the solution to DE in y
tvec = -.25:.1:3.75; %defines time range for the output presentation
y=NaN*zeros(1,length(tvec)); %NAN is not a number (no value is defined as o/p)
for t = tvec, % Start of loop for convolution, here t is scalar value varies in loop
ti=ti+1; % incrementing the counter pointer for the solution to DE in y
xh= x(tau).* h(t-tau); % Multiplication of two signals
y(ti) = sum(xh.*dtau); % integration
subplot(2,1,1),plot(tau,x(tau),'k-',tau,h(t-tau),'k--',t,0,'ok');
% This window is for the display of the overlap ranges of two signals
axis([tau(1) tau(end) -0.25 1.25]);
subplot(2,1,2),plot(tvec,y,'k',tvec(ti),y(ti),'ok'); % This window is for the display of output
axis([tau(1) tau(end) -0.25 3.4]);
drawnow; pause;
end
figure; plot(tvec,y) % output is sketched in new window
2|Page
Finding Total Response: (using Classical Method)
For the same above example, with the input x(t) = 2t+3,
Manually calculate Q(D) x(t) as: (3D+5) {x(t)} = 3D {(2t+3)} + 5 {(2t+3)} = 10t+21.
Then, include these terms in the set of differential equation 1 and 2a along with the given boundary
conditions (initial conditions).
Note: while finding the total response, it uses initial conditions rather than auxiliary conditions.
Exercises
1. For the following LTIC system, find and sketch yo(t), the zero input component of the response
y(t), for t ≥ 0, if the initial conditions are y(0-) = 2 ; dy(0-)/dt = -1; d2y(0-)/dt2 = 1 using MATLAB.
Also find & sketch zero state component of the response, if x(t) = u(t),e-2tu(t),sin(3t)u(t), e-3tu(t).
Verify the above results manually, by identifying the characteristic polynomial, characteristic roots,
characteristic modes of the system. Sketch the total output responses and comment on the nature of
the responses (belongs to what class of signal model).
a) D(D+1)y(t) = (D+2)x(t)
b) (D2+9)y(t) = (3D+2)x(t)
c) (D2+4D+13)y(t) = 4(D+2)x(t)
d) D2 (D+1)y(t) = (D2+2)x(t)
e) (D2+4D+4)y(t) = 4(D+2)x(t)
2. Find the unit impulse response of a system specified by the equations in exercise no.1.
3. For the following unit impulse responses of an LTIC system h(t), find the Zero State response y(t),
if the given following input x(t). Comment on the Nature (characteristic polynomial, characteristic
roots, characteristic modes), stability, and find the time constant of the system. Sketch the output
responses and comment on the nature of the responses (belongs to what class of signal model).
Comment on the cut-off frequency and filtering action (by suitably changing the forcing function
frequency).
a) h(t) = (1-3t)e-2tu(t) ; x(t) = u(t),e-2tu(t),sin(3t)u(t)
b) h(t) = sin(3t)u(t) ; x(t) = u(t),e-tu(t),(2t+3)e-2tu(t), sin(3t)u(t), e-0.1tsin(3t)u(t) sin(2.9t)u(t),
e-0.1tsin(2.9t)u(t)
In these cases, observe/comment on the resonance effect.
c) h(t) = 4e-2tcos3t u(t) x(t) = u(t),e-3tu(t),(2t+3)e-2tu(t)
d) h(t) = e-t u(t) ; x(t) = e-2tu(t),e-2(t-3)u(t), e-2tu(t-3)
1
4. Sketch the functions x(t ) = 2 and u(t). Now find x(t) * u(t) for various time range and sketch
t +1
the result. Select the appropriate presentation ranges while using the convolution.
5. Figure below shows x(t) and g(t). Find & sketch c(t) = x(t) * g(t). What are the changes in c(t), a)
if the signal x(t) is everlasting, b) if the signal x(t) is everlasting and if the frequency of the signal
x(t) is changed. Comment on the output signal duration and pattern of variation of c(t). What is the
mathematical expression for c(t) (to be calculated manually) ?
3|Page
x(t) sin t
1
g(t)
g(t) 1
1
0 2 t
0
t
2 t
g(t) g(t)
3 3 Fig.1
2 2
1 1
-1 0 1 2 t (secs) 01 1 2 3 4 5 6 7 t
6. The periodic signal x(t) shown in the following Fig.2, is input to a system with impulse response
function, h(t) = t[u(t)-u(t-1.5)]. Use convolution to determine the output y(t) of this system. Plot
y(t) over (-3 ≤ t ≤ 3). If x(t) variation is t instead of t2, observe how is the output variation? What is
the mathematical expression for y(t) ? x(t)
t2 Fig.2
-5 -4 -3 -2 -1 0 1 2 3 4 5 t (secs)
7. Explain with reasons, whether the LTIC system described by the following equations are
i) Externally stable or unstable (in the BIBO sense)
ii) Internally asymptotically stable, unstable, or marginally stable.
a) (D2+8D+12) y(t) = (D-1) x(t)
b) D(D2+3D+2)y(t) = (D+5)x(t)
c) D2 (D2+2)y(t) = x(t)
d) (D+1)(D2-6D+5)y(t) = (3D+1)x(t)
e) (D+1) (D2+2D+5)2 y(t) = x(t)
f) (D+1)(D2+9)y(t) = (2D+9)x(t)
g) (D+1)(D2+9)2 y(t) = (2D+9)x(t)
h) (D2+1)(D2+4)(D2+9)y(t) = (3D)x(t)
Plot the typical forced response, ZSR (assuming suitable forcing function) and free (natural)
responses in each case, and identify / observe / comment on the intuitive insights into system
behaviors and /or solving the equations.
4|Page