Professional Documents
Culture Documents
LABSHEET EXCERCISE -1
1.Type the following commands and observe closely what happens after each instruction
1b) x= sqrt(4)
x=
1c) y=sqrt(9)
y=
1d) who
x y
1e) Who
1f)whos
x 1x1 8 double
y 1x1 8 double
1g) z=sin(3.14)
z=
0.0016
1h) whos
x 1x1 8 double
y 1x1 8 double
z 1x1 8 double
1i) clc
1j) who
x y z
1k) clear
1l) who
no variable appears
1m) size(x)
1n) a=[1 2 3]
a=
1 2 3
b=[3 4 5]
b=
3 4 5
>> a*b
>> a.*b
ans =
3 8 15
1o) C=[a b]
C=
1 2 3 3 4 5
1p) zeros(4)
ans =
0 0 0 0
0 0 0 0
0 0 0 0
0 0 0 0
1q)zeros(1,3)
ans =
0 0 0
1r)ones(1,2)
ans =
1 1
1s)P=[zeros(1,3) 1 1 ones(1,2)]
P=
0 0 0 1 1 1 1
1u.Y=1:0.5:5
Y=
Columns 1 through 7
Columns 8 through 9
4.5000 5.0000
1v.M=[1 2 3
456
7 8 9]
M=
1 2 3
4 5 6
7 8 9
>> fprintf('%f\n',M);
1.000000
4.000000
7.000000
2.000000
5.000000
8.000000
3.000000
6.000000
9.000000
??? X= M[1,:]
|
Error: Unbalanced or unexpected parenthesis or bracket.
2.
2a) Method 1
A=[ 3 12 6 8
5 3 9 11
1 2 14 7
10 5 3 6]
A=
3 12 6 8
5 3 9 11
1 2 14 7
10 5 3 6
Method 2
A=[3 12 6 8;5 3 9 11;1 2 14 7;10 5 3 6]
A=
3 12 6 8
5 3 9 11
1 2 14 7
10 5 3 6
Method 3
A=[3,12,...
6,8
5,3,...
9,11
1,2,...
14,7
10,5,...
3,6]
A=
3 12 6 8
5 3 9 11
1 2 14 7
10 5 3 6
Method 4
A=[3,12,6,8;5,3,9,11;1,2,14,7;10,5,3,6];
>> disp(A)
3 12 6 8
5 3 9 11
1 2 14 7
10 5 3 6
2b) Y=A'
Y=
3 5 1 10
12 3 2 5
6 9 14 3
8 11 7 6
Z=inv(A)
Z=
2c) B=size(A)
B=
4 4
2d) X= A(2,1:4)
X=
5 3 9 11
>> Y=A(1:4,3)
Y=
14
3
2e) X*Y
ans =
216
2h)
fprintf('%f',a)
fprintf('%f\n',a)
3.000000
5.000000
1.000000
10.000000
12.000000
3.000000
2.000000
5.000000
6.000000
9.000000
14.000000
3.000000
8.000000
11.000000
7.000000
6.000000
>>
2f) X.*Y
2g) A(4,:)=[1 5 9 0]
A=
3 12 6 8
5 3 9 11
1 2 14 7
1 5 9 0
2i) fliplr(A)
ans =
8 6 12 3
11 9 3 5
7 14 2 1
6 3 5 10
2j) D=diag(A)
D=
3
3
14
6
2k) V=diag(diag(A))
V=
3 0 0 0
0 3 0 0
0 0 14 0
0 0 0 6
2l)Z=eye(4)
Z=
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
2m) cat(2,A,Z)
ans =
3 12 6 8 1 0 0 0
5 3 9 11 0 1 0 0
1 2 14 7 0 0 1 0
10 5 3 6 0 0 0 1
3.w=(0:0.01:1)
w=(0:0.01:1)
w=
Columns 1 through 7
Columns 8 through 14
Columns 15 through 21
Columns 22 through 28
Columns 36 through 42
Columns 43 through 49
Columns 50 through 56
Columns 57 through 63
Columns 64 through 70
Columns 71 through 77
Columns 78 through 84
Columns 85 through 91
Columns 92 through 98
length(w)
ans =
101
4) x=[1 6 9 2]
x=
1 6 9 2
>> y=[2 0 3 8]
y=
2 0 3 8
>> x+y
ans =
3 6 12 10
>> x.*y
ans =
2 0 27 16
5) conj(3+7i)
ans =
3.0000 - 7.0000i
>> j=ans
j=
3.0000 - 7.0000i
>> abs(j)
ans =
7.6158
>> phase(j)
ans =
-1.1659
only the variables names, not the function to which each variable
are listed.
WHO GLOBAL and WHOS GLOBAL list the variables in the global workspace.
WHO -FILE FILENAME lists the variables in the specified .MAT file.
WHO ... VAR1 VAR2 restricts the display to the variables specified. The
in the workspace or file. You must use the functional form of WHO when
WHOS -REGEXP PAT1 PAT2 can be used to display all variables matching
the specified patterns using regular expressions. For more information
on using regular expressions, type "doc regexp" at the command prompt.
8.B=sym(x^2+5*x+6)
B=
x^2 + 5*x + 6
>> solve(B)
ans =
-3
-2
9. E=[1 5 6]
E=
1 5 6
roots(E)
ans =
-3.0000
-2.0000
10. U=[ 4 5 6 7]
U=
4 5 6 7
>> mean(U)
ans =
5.5000
>> median(U)
ans =
5.5000
sum(U)
ans =
22
11. y=int('x^2')
y=
1/3*x^3
12.y=int('x^3+x^2+1',0,5)
y=
2435/12