t = 0:0.0001:0.07;
v0 = input('please Enter the value for v0:');
R = input('please Enter the value for resistance:');
C = input('please Enter the value for capacitacne:');
f = input('please Enter the value for frequency:');
m = length(t);
state = 'on';
for A = 1:m
vs(A) = v0 * sin(2*pi*f*t(A)); switch state case 'on' vR(A) = vs(A); iR = vR(A)/R; iC = 2*pi*f*C*v0*cos(2*pi*f*t(A)); I = iC + iR; if I<=0 state = 'off'; tA = t(A); end case 'off' vR(A) = v0*sin(2*pi*f*tA)*exp(-(t(A)-tA)/(R * C)); if vs(A) >= vR(A) state = 'on'; end endend
plot (t,vs,':',t,vR,'k')
thanks…
Best Answer