Sheet 2
Sheet 2
Experiment [2]
Matrix Functions
1
Engineering Analysis Laboratory
Let A=
16 3 2 13
5 10 11 8
9 7 6 9
4 15 14 1
>>sum(A)
ans=
34 35 33 31
>>A'
ans=
16 5 9 4
3 10 7 15
2 11 6 14
13 8 9 1
>>diag(A)
ans=
16
10
6
1
>>tril(A)
ans=
16 0 0 0
5 10 0 0
9 7 6 0
4 15 14 1
>>triu(A)
ans=
16 3 2 13
0 10 11 8
0 0 6 9
0 0 0 1
>> size(A)
ans=
4 4 (means that A has 4 rows and 4 columns)
>> fliplr(A)
2
Engineering Analysis Laboratory
ans =
13 2 3 16
8 11 10 5
9 6 7 9
1 14 15 4
>> flipud(A)
ans =
4 15 14 1
9 7 6 9
5 10 11 8
16 3 2 13
>>z = zeros(2,4)
z=
0 0 0 0
0 0 0 0
>> [m,n]=size(A)
m=
4
n=
4
>> f=5*ones(3,3)
f=
5 5 5
5 5 5
5 5 5
>> N=fix(10*rand(1,10))
N=
9 2 6 4 8 7 4 0 8 4
>>R=randn(1,4)
R=
3
Engineering Analysis Laboratory
Experiment:
Q1) What is the result of the following command:
>> Sum (A’)
>> Sum (A)’
>> Sum (diag (A))
>> Sum (triu (fliplr (A’)))
>> Sum (diag (flipud (A’)’)’)’
Q2) Given the array:
A=
1 4 3 2
4 1 2 5
3 3 5 1