Analizing the charges and discharges of a capacitor conected to a square wave voltage source

조회 수: 1 (최근 30일)
I'm trying to find an equation that replicates the values of the voltage of the capacitor in a circuit with a resistor of 100k ohms.
I have the equations but I dont know how to code them in matlab.
So far I've accomplished the first half of the cycle but I can't get the other half right.
Pls help.
It is a square voltage source with a freecuency of 1000Hz and the two voltages are 10 and 0.
function y = fcn(u,t0)
if u < t0
y = 0;
else
if u > 0.5e-3
y = 9.93*exp(-10000*(u-t0));
else
y = -10*exp(-10000*(u-t0))+10;
end
end

채택된 답변

David Goodmanson
David Goodmanson 2020년 6월 5일
Hello Virginia,
As you progress along the square wave, each time you get to a new half cycle there is of course a new applied voltage Vapp, alternating between 10 and 0 volts. When that occurs, the capacitor is sitting at a voltage I'll call Vold. At that point the voltage moves toward the new Vapp with a time constant 1e-4 that you know already. If the start of that half cycle is denoted by u = tstart, then the voltage in the half cycle is
V = Vapp + (Vold - Vapp)*exp(-(u-tstart)*10000)
So as you can see, for u = tstart the voltage is Vold, and as u--> inf the voltage --> Vapp. So all you need do is start with Vold = 0, go through each half cycle, find the voltage as a function of u, and then use Vold = V(end of that half cycle) for the start of the upcoming half cycle.
  댓글 수: 1
Virginia Martin Herrera
Virginia Martin Herrera 2020년 6월 6일
thank you!!! I only need the graphic for one cycle, that’s why I used ifelse. So as you say, en each function I have to “restart” the time cause the equations that I have start at 0. What I did was adding 5e-4 inside de parenthesis and it worked. Thank you very mucho for your answer!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by