Plot a Charge and Discharge of a Capacitor in MATLAB

0

I need to create a program that shows through the plot the loading and discharge of a capacitor according to the images below:

Thereare3constantswheretheusermustentervalues:C=capacitance;R=resistanceE=sourcevoltage(example,a20vsource);

Iwasabletographtheloadthroughthiscode:

    
asked by anonymous 06.05.2016 / 16:02

1 answer

2

If you want to do the theoretical chart, just continue the same way you started by asking for the values and showing the figure for each case. You can show the result in the same figure or separate figures. I recommend using a time t dependent on the value of Tau. A capacitor charges / discharges totally in 5 * Tau, so the following code shows figures always adjusted to the value of Tau.

C = input ('Digite o valor do condensador (em uF): ')
R = input ('Digite o valor da resistencia (em Ohms): ')
E = input ('Digite o valor da fonte de tensao (em V): ')

C = 10^-6
Tau = R * C;

t = linspace (0,5*Tau,100); %100 amostras de 0 a 5*Tau segundos

figure (1)
hold on
% carga do capacitor
plot (t,E*(1-exp(-t/(R*C))),'b-')

% descarga do capacitor
%figure (2)  %para graficos separados descomente essa linha
plot (t,E*(exp(-t/(R*C))),'r-')
    
13.12.2016 / 16:09