How to plot a capacitor charging and discharging
51 次查看(过去 30 天)
显示 更早的评论
I'm trying to plot the charging and then discharging of a capacitor in a simple RC circuit. I need it to be 3 complete cycles a 1kHz. The code I wrote just gives me 6 separate line segments. I can see why I'm not getting the plot that I want but I don't know how to get the plot that I want. Could anyone help me out with this please? Here is my code. I have all of the component values listed in the code. Like I said, it's pretty obvious why it's wrong. I just have no idea how to make it right.
t1=0:0.00001:0.005;
t2=0.005:0.00001:0.01;
t3=0.01:0.00001:0.015;
t4=0.015:0.00001:0.02;
t5=0.02:0.00001:0.025;
t6=0.025:0.00001:0.03;
v=5;
r=10e3;
c=10e-7;
tau = r*c;
v1=v.*exp(t1/tau);
hold on
v2=v.*exp(-t2/tau);
hold on
v3=v.*exp(t3/tau);
hold on
v4=v.*exp(-t4/tau);
hold on
v5=v.*exp(t5/tau);
hold on
v6=v.*exp(-t6/tau);
hold on
plot(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6)
hold on
0 个评论
采纳的回答
更多回答(1 个)
Preethi
2016-11-30
hi,
Since you are using separate variables which doesn't have any common values you might be getting separate lines. Try this at the end, you can remove 'hold on' also
t=[t1,t2,t3,t4,t5,t6];
vf = [v1,v2,v3,v4,v5,v6];
plot(t,vf)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Circuit Envelope Simulation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!