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 onv2=v.*exp(-t2/tau);hold onv3=v.*exp(t3/tau);hold onv4=v.*exp(-t4/tau);hold onv5=v.*exp(t5/tau);hold onv6=v.*exp(-t6/tau);hold onplot(t1,v1,t2,v2,t3,v3,t4,v4,t5,v5,t6,v6)hold on
Best Answer