voltage across a capacitor in a simple RC circuit
.
% This code plots the charging and discharging voltage of a capacitor.
clc;clear
R = 1e3; % Resistance in ohms
C = 1e-6; % Capacitance in farads
V0 = 5; % Initial voltage in volts
tau = R*C; % Time constant
t = linspace(0, 5*tau, 1000); % Time vector
% Charging voltage
Vc_charge = V0*(1-exp(-t/tau));
% Discharging voltage
Vc_discharge = V0 * exp(-t/tau);
plot(t,Vc_charge , t,Vc_discharge)
title('Capacitor Voltage')
xlabel('Time (s)')
ylabel('Voltage (V)')
legend('Charging', 'Discharging')



دیدگاهها
هیچ نظری هنوز ثبت نشده است.