Home / Circuits with Matlab / RC Circuit Analysis using Matlab

RC Circuit Analysis using Matlab

Determine the voltage across the capacitor:

RC Circuit

Let us compute the voltage across the capacitor for t≥0 using the following expression:

${{v}_{C}}(t)={{V}_{c0}}{{e}^{-t/\tau }}u(t)$

Whereas the capacitor initial voltage is 5V and time constant τ=RC=0.2s.

It’s time to write some code in Matlab to calculate the capacitor voltage:

Matlab Code for RC Circuit

%RC Circuit Analysis
clear all;close all;clc
%%Circuit Parameters
R= 2e3; % Resistance (2kOhm)
C= 100e-6; % Capacitance (100microFarad)
tau=R*C; % Circuit Time Constant 
Vco=5; % Capacitor initial Voltage at t=0
Time=0:tau/100:5*tau; % Sampling Time
Vc=Vco.*exp(-Time./tau).*heaviside(Time);
 
%%Plotting the Result
plot(Time,Vc)
xlabel('Time (s)')
ylabel('Amplitude (V)')
title('V_C')
axis([0 5*tau 0 6]) % Manual Axis Limits adjustment 
%=============================================

Results:

Capacitor Discharging Voltage

About Ahmad Faizan

Mr. Ahmed Faizan Sheikh, M.Sc. (USA), Research Fellow (USA), a member of IEEE & CIGRE, is a Fulbright Alumnus and earned his Master’s Degree in Electrical and Power Engineering from Kansas State University, USA.

Check Also

Average Power RMS Voltage RMS Current Power Factor Calculation using Matlab

In this tutorial, we will calculate average power, RMS Voltage, RMS Current as well as …

Leave a Reply