Simulation of the time-domain analytical solution using Matlab command line

We have shown previously that the analytical solution of the output voltage dropped across a capacitor of an RC circuit,

RC circuit

RC circuit

subjected to 2V Step Input, is given by:

Equation 3

Equation 3

We can easily compute the output voltage as a function of time t, values of R and C, using one of the most popular tools for control system design and analysis, namely Matlab, as follows.

1. Create an m-file or m-script as shown below or download this m-file (sim_rc_cct.m).

% Simulate and plot response of a RC circuit

%% Preparation
clear all, close all
tfinal = 1 % Final simulation time sec
t = 0:0.01:tfinal; % Define simulation time from 0 to tfinal seconds at 0.01 interval
R = 1e3 % Define resistor values (Ohm)
C = 100e-6 % Define capacitor values (Farad)

%% Actual computation
v_out = 2-2*exp(-t/(R * C))

%% Plotting the output response
title([‘V_{out} (volts) for RC circuit (R=’ num2str(R) ‘\Omega, C=’ num2str(C) ‘F)’])
xlabel(‘Time (sec)’)
ylabel(‘V_{out} (V)’)
grid on

2. Run the m-file and see the simulation results

RC Circuit Simulation using Matlab Command Line (m-file)


Video Tutorials