PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

278 Practical MATLAB® Applications for Engineers


The RMS value of f1(t) is =
3.5355339059327376220042218105243
The average value of f2(t) is =
.50000000000000000000000000000000
The RMS value of f2(t) is =
.57735026918962576450914878050196
The average value of f3(t) is =
.50000000000000000000000000000000
The RMS value of f3(t) is =
.70710678118654752440084436210485
**********************************************************************
% Script file: ave _ rmst _ num
% evaluates the average and rms values of f1,f2 and f3
% using numerical techniques (trapz)
t1= linspace(0,3,100);
y1= 5*cos(2*pi/3*t1);
avecos =1/3*trapz(t1,y1);
y1sq = y1.^2;
rmscos = sqrt(1/3*trapz(t1,y1sq));
t2 =linspace(0,1,100);
y2 = t2;
avesaw = trapz(t2,y2);
y2sq = y2.^2;
rmssaw = sqrt(trapz(t2,y2sq));
y3 = [ones(1,50) zeros(1,50)];
avesqr = trapz(t2,y3);
y3sq = y3.^2;
rmssqr = sqrt(trapz(t2,y3sq));
disp(‘*********************************************************’);
disp(‘ ********* Numerical Results (using trapz)***********’);
disp(‘*********************************************************’);
disp(‘ ’)
disp(‘The average value of f1(t) is =’)
disp(avecos)
disp(‘The rms value of f1(t) is =’)
disp(rmscos)
disp(‘ ’)
disp(‘The average value of f2(t) is =’)
disp(avesaw)
disp(‘The rms value of f2(t) is =’)
disp(rmssaw)
disp(‘ ’)
disp(‘The average value of f3(t) is =’)
disp(avesqr)
disp(‘The rms value of f1(t) is =’)
disp(rmssqr)
disp(‘**************************************************’)
The script fi le ave_rms_num is executed and the results are as follows:
>> ave _ rms _ num
*********************************************************
******** Numerical Results (using trapz) *************
*********************************************************
Free download pdf