PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

36 Practical MATLAB® Applications for Engineers


MATLAB Solution
% Script file: sincs
x = -5:0.1:5;
y = sinc(x);
plot(x, y)
title(‘sinc(x) vs. x for -5<x<5’)
xlabel(‘x’);
ylabel(‘Amplitude [Sinc(x)]’);
grid on;

R.1.111 The MATLAB function tripuls(t, c) returns a symmetric triangle with its base along
the horizontal axis, with length c, centered at t = 0.


R.1.112 For example, create the script fi le triang that returns the plots of triangles with the
following specs:
a. f 1 (t) versus t, with peak[f 1 (t)] = 1 and a base length = 3
b. f 2 (t) versus t, with peak[f 2 (t)] = 2 and a base length = 5
c. f 3 (t) versus t, with peak[f 3 (t)] = 3 and a base length = 10
d. f 4 (t) versus t, with peak[f 4 (t)] = 4 and a base length = 12


MATLAB Solution
% Script file: triang
t = -6:0.1:6;
f1 = tripuls(t,3);
f2 = 2*tripuls(t,5);
f3 = 3*tripuls(t,10);
f4 = 4*tripuls(t,12);
subplot(2,2,1)
plot(t,f1)
ylabel(‘Amplitude [f1(t)]’);
xlabel(‘ t (time)’)
axis([-6 6 -0.5 1.5])
title(‘tripuls(t,3) vs. t’)
subplot(2,2,2)
plot(t,f2)
ylabel( ‘Amplitude [f2(t)]’)
xlabel(‘ t (time)’)
axis([-6 6 -0.5 2.5])
title(‘2*tripuls(t,5) vs. t’)
subplot(2,2,3)
plot(t,f3)
axis([-6 6 -0.5 4.5])
ylabel(‘ Amplitude [f3(t)] ‘);xlabel(‘ t (time)’)
title(‘3*tripuls(t,10) vs. t’)
subplot(2,2,4)
plot(t,f4)
axis([-6 6 -0.5 5.5])
title(‘4*tripuls(t,12) vs. t’)
ylabel(‘ Amplitude [f4(t)] ‘); xlabel(‘ t (time) ‘)

The script fi le triang is executed and the results are shown in Figure 1.33.


R.1.113 The MATLAB function rectpuls(t, d) returns a symmetric rectangle with width d,
centered at t = 0.

Free download pdf