PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

184 Practical MATLAB® Applications for Engineers


then
vR(t) = V 0 − vC(t) = Ve−t/ for R = 1, 2, and 5 Ω

and

it()
vt
R

V
R

R et
() 0 /

where τ = RC.

MATLAB Solution
% Script file:RC
vctR _ 1=dsolve(‘0.5*Dy+y=10’,’y(0)=0’,’t’);
vctR _ 2=dsolve(‘Dy+y=10’,’y(0)=0’,’t’);
vctR _ 5=dsolve(‘2.5*Dy+y=10’,’y(0)=0’,’t’);
disp(‘****************************************’);
disp(‘********** R E S U L T S **************’)
disp(‘****************************************’);
disp(‘The voltages across C for R=1,2 and 5(in volta)are:’);
disp(‘****************************************’);
vctR _ 1
disp(‘****************************************’);
vctR _ 2
disp(‘****************************************’);
vctR _ 5
disp(‘****************************************’);
figure(1)
ezplot(vctR _ 1,[0 4]);
hold on
ezplot(vctR _ 2,[0 4]);
hold on
ezplot(vctR _ 5,[0 4]);
hold on
grid on;axis([0 3 0 11])
xlabel(‘time t/sec’)
ylabel(‘voltage ‘)
title(‘Voltages across C for R=1,2 and 5 are:’)
figure(2)
disp(‘The voltages across R’)
disp(‘ for R=1,2 and 5 (in volts) are:’);
disp(‘****************************************’);
vr1=10-vctR _ 1
disp(‘****************************************’);
vR2=10-vctR _ 2
disp(‘****************************************’);
vR5=10-vctR _ 5
disp(‘****************************************’);
ezplot(10-vctR _ 1,[0 4]);
hold on
ezplot(10-vctR _ 2,[0 4]);
hold on
ezplot(10-vctR _ 5,[0 4]);
hold on
Free download pdf