


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Matlab lab practice exercises covering matrix operations, signal generation, and plotting. The exercises include creating matrices, performing element-wise and matrix multiplication, generating signals using various functions, and plotting the results. Students will learn how to use matlab to manipulate matrices and signals, making it an essential resource for those studying signal processing, linear algebra, or engineering.
Typology: Exercises
1 / 26
This page cannot be seen from the preview
Don't miss anything!



















v=[1 2;3 4] v= 1 2 3 4 (a) v(2) ans = 3 w=[2 3;5 6] w = 2 3 5 6 (b) sum=v+w sum = 3 5 8 10 (c) diff=v-w diff = -1 - -2 -
(d) vw=[v w] vw = 1 2 2 3 3 4 5 6 (e) vw(2:6) ans = 3 2 4 2 5 (f) v' ans = 1 3 2 4
w=[3 2 1;5 4 3;8 7 6] w = 3 2 1 5 4 3 8 7 6 (c)[v;w] ans = 3 2 1 5 4 3 7 6 8 3 2 1 5 4 3 8 7 6 (d) v*z ans = 18 24 30 42 54 66 87 108 129
v' ans = 3 5 7 2 4 6 1 3 8 (e) [z;v'] ans = 1 2 3 4 5 6 7 8 9 3 5 7 2 4 6 1 3 8 (f) z+v' ans = 4 7 10 6 9 12 8 11 17
z=[444 333;222 666] z = 444 333 222 666 (e) Mz(1:2) Error using * Inner matrix dimensions must agree. v=[222 444;777 333] v = 222 444 777 333 (f) v(3:4)M ans = 209457 381951 (g) M(1,1) ans = 222 (h) M(1:2,1:2) ans = 222 444 333 555
ans = 222 333 (J)M(2,:) ans = 333 555
(3) det() Description: det(X) returns the determinant of the square matrix X. If X contains only integer entries, the result d is also an integer. det(m) ans =
(4)Linspace () Description: The linspace function generates linearly spaced vectors. It is similar to the colon operator ":", but gives direct control over the number of points. y = linspace(a,b) generates a row vector y of 100 points linearly spaced between and including a and b. y = linspace(a,b,n) generates a row vector y of n points linearly spaced between and including a and b.
y = linspace(2,3); y = linspace(2,3); y = linspace(2,3) y = Columns 1 through 12
- 2.0000 2.0101 2.0202 2.0303 2.0404 2.0505 2.0606 2.0707 2. Columns 25 through 36 0.0091 0.0110 0.0133 0.0160 0.0193 0.0233 0.0281 0.0339 0. 0.0494 0.0596 0. Columns 37 through 48 0.0869 0.1048 0.1265 0.1526 0.1842 0.2223 0.2683 0.3237 0. 0.4715 0.5690 0. Columns 49 through 50 0.8286 1. EXERCISE#
t=linspace(0,20,100) yc=cos(t) plot(t,y)
t=linspace(0,20,100) yc=cos(t) plot(t,yc,'r') hold on ys=sin(t) plot(t,ys) legend('yc','ys')
t=linspace(0,20,100) yc=cos(t) subplot(311) plot(t,yc,'r') legend('yc') hold on ys=sin(t) subplot(312) plot(t,ys) legen
(i)>> help whos whos List current variables, long form. whos is a long form of WHO. It lists all the variables in the current workspace, together with information about their size, bytes, class, etc. (ii)>> help pwd pwd Show (print) current working directory. pwd displays the current working directory. S = pwd returns the current directory in the string S. (iii)>>help hold hold Hold current graph hold ON holds the current plot and all axis properties so that subsequent graphing commands add to the existing graph. hold OFF returns to the default mode whereby PLOT commands erase the previous plots and reset all axis properties before drawing new plots. hold, by itself, toggles the hold state. hold does not affect axis autoranging properties.
A= f0=4pi w=pi/ t=0:0.001: y=asawtooth(f0*t+w) plot(t,y);
A= f0=10pi w=5pi t=0:0.001: sq=Asquare(f0t+w) plot(t,sq) axis([0 1 -2 2])
A= f0=pi/ w=pi/ n=-10:1: x=Asquare(f0n+w) stem(n,x)
EXERCISE# (A) fo=10pi w=5pi A= n=-10:1: x=Asawtooth((fon+w)/2) stem(n,x) (B) (i) a= w=20pi Q=pi/ t=0:0.001: x=acos(wt+Q) plot(t,x) (B) (ii) a= w=20pi Q=pi/ t=0:0.001: x=asin(wt+Q) plot(t,x)
(D) t=0:0.001: z=2.exp(-t).cos(2.5pit).(t>0.2) plot(t,z) (E) n=0:0.001: y=60.exp(-6n).sin(20pin) plot(n,y)
EXERCISE# (A) (i) n=0:0.001: Un=1(n>=0) x=Un.n stem(n,x) (A) (ii) n=-100:1: x=1.(n==0) stem(n,x) (A) (iii) n=-5:0.5: x=(n-2).((n-2)>0) R=2.*x stem(n,R) grid on