PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

34 Practical MATLAB® Applications for Engineers


R.1.108 For example, create the script fi le triangles that returns the plots over two cycles of
the triangular sequences, with period T = 2 π, with the following specs:
a. f 1 (t) versus t, with positive slope during 50% of the period T, and a swing from
− 1 to + 1
b. f 2 (t) versus t, with positive slope during 25% of the period T, and a swing from
− 2 to + 2
c. f 3 (t) versus t, with a positive slope during 33% of the period T, and a swing from
− 3 to + 3
d. f 4 (t) versus t, with a positive slope during 75% of the period T, and a swing from
− 4 to + 4


MATLAB Solution
% Script file: triangles
t = 0:0.1*pi:4*pi;
f1 = sawtooth(t,.5);
f2 = 2*sawtooth(t,.25);
f3 = 3*sawtooth(t,.33);
f4 = 4*sawtooth(t,.75);
subplot(2,2,1)
plot(t,f1)
ylabel (‘f1(t)’)
axis ([0 4*pi -1.5 1.5])
grid on;
title (‘Sawtooth(t,.50) vs t’)
subplot(2,2,2)
plot(t,f2)
ylabel( ‘f2(t)’)
axis ([0 4*pi -2.5 2.5])
grid on;
title (‘2*Sawtooth(t,.25) vs t’)
subplot (2,2,3)
plot (t,f3)
axis ([0 4*pi -4.5 4.5])
grid on;
ylabel(‘ f3(t) ‘);xlabel(‘ t (time)’)
title(‘3*Sawtooth(t,.33) vs t’)
subplot(2,2,4)
plot(t,f4)
axis([0 4*pi -5.5 5.5])
grid on;
title(‘4*Sawtooth(t,.75) vs t’)
ylabel(‘ f4(t) ‘); xlabel(‘ t (time) ’)

The script fi le triangles is executed and the results are shown in Figure 1.31.


R.1.109 The MATLAB function sinc(x) evaluates the function defi ned by


sin ( )
sin( )
cx
x
x










R.1.110 For example, the script fi le sincs returns the plot of the function sinc(x) over the
range 5 ≤ x ≤ 5 , illustrated in Figure 1.32.

Free download pdf