Numerically solving second-order RLC natural response using Matlab

I remember that I only got a C+ for the subject of electric circuit II. It faithfully reflected my understanding of the subject. It was unclear to me, but fortunately I passed. Recently I revisited the subject of RLC natural response again because I wanted to analyze the performance of  a step up transformer based high voltage generator. For that reasons, I needed to derive RLC characteristic equations, and then solved it numerically in Matlab. After doing the problems for some time, I think now I have a better understanding.

I want to immortalize my notes in this blog. So I can look back to these notes in case I forget how to solve them in the future. Hopefully, you find them useful too 🙂


% Numerically solving RLC natural response using
% Ordinary Differential Equation (ode) solver
%% -----Rp-------Rs----
%  |         |        |
%  C         L       Rl
%  |         |        |
%  --------------------
clear all;

C = 100 * 10^(-6);
L = 7 * 10^(-3);
Rl = 50;
Rs = 5;
Rp = 2;
Vc = 100;

a = (Rs+Rp+Rl)*L/(Rs+Rl);         %from equation (5)
b = (C*Rp*(Rs+Rl)+L)/(C*(Rs+Rl)); %from equation (5)
c = 1/C;                          %from equation (5)

tspan = [0 0.05];
init = 0;                             %i(0+)
init2 = ((Rs+Rl)*Vc)/((Rs+Rp+Rl)*L);  %di/dt (0+)
y0 = [init; init2];
[t, y] = ode45(@(t,y) [y(2); (-c*y(1)-b*y(2))/a], tspan, y0);
i3 = y(:,1);
i2 = y(:,2)*(L/(Rs+Rl));  %from equation (3)
i1 = -(i2+i3);            %from equation (1)

grid on
xlabel('time (seconds)')
ylabel('V_{RL} (volts)')

Here is the result….

rlc natural response.png

I have verified the result by comparing with a free circuit simulation software LTSPICE IV. Here is the circuit file, if you want to check.