PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

Alternating Current Analysis 277


MATLAB Solution
% Script file : ave _ rms _ sym
% returns the functions f1,f2,& f3
% and computes the average and rms values of f1,f2 & f3
% using symbolic (int) technique
x = linspace(-3,3,100);
f1t = 5.*cos(2*pi./3.*x);
subplot(3,1,1)
plot(x,f1t);
title(‘Plots of f1(t),f2(t) & f3(t)’);
ylabel(‘f1(t)’),axis([-3 3 -6 6]);
subplot(3,1,2)
a = linspace(0,1,25);
y = [a a a a];x=linspace(-1,3,100);
plot(x,y);ylabel(‘f2(t)’);axis([-1 3 -.5 1.5]);
b = [ones(1,12) zeros(1,13)];bb = [b b b b];subplot(3,1,3)
plot(x,bb);ylabel(‘f3(t)’);axis([-1 3 -.5 1.5]); xlabel(‘time’);
% Figure 3.58
syms t;
w = 2*pi/3;
T = 2*pi/w;
f1ave=1/T*int(5*cos(w*t),0,T); % part(a)
disp(‘****************************************************’);
disp(‘************Symbolic Results (using int )*********’);
disp(‘****************************************************’);
disp(‘The average value of f1(t) is =’);
ans1=vpa(f1ave);disp(ans1);
f1rms=sqrt(1/T*int(25*cos(w*t)^2,0,T)); % part(b)
disp(‘The RMS value of f1(t) is =’);
ans2=vpa(f1rms);disp(ans2);
T1=1;
w1=2*pi/T1;
Vave2 = 1/T1*int(t,0,T1);%part(b)
disp(‘The average value of f2(t) is =’);
ans3 = vpa(Vave2); disp(ans3);
Vrms2 =sqrt(1/T1*int(t^2,0,T1));
disp(‘The RMS value of f2(t) is =’);
ans4 = vpa(Vrms2); disp(ans4);
w2 = 2*pi/T1;
Vave3 =1/T1*int(sym(‘Heaviside(t)’),0,T1/2); %part(c)
disp(‘The average value of f3(t) is =’);
ans5 = vpa(Vave3);disp(ans5);
Vrms3 =sqrt(1/T1*int(sym(‘Heaviside(t)^2’),0,T1/2));
disp(‘The RMS value of f3(t) is =’);
ans6 = vpa(Vrms3);disp(ans6);
disp(‘****************************************************’);
The results of executing the script fi le ave_rms_sym are shown as follows:
>> ave_rms_sym
************************************************************
************* Symbolic Results ( using int) **************
************************************************************
The average value of f1(t) is =
0
Free download pdf