0% found this document useful (0 votes)
33 views

Homework: Answer

The document contains the solutions to multiple homework exercises involving matrix operations in MATLAB. It includes the code used to perform operations like matrix multiplication, addition, subtraction, transposition, and determining the inverse, determinant, eigenvalues and eigenvectors of matrices. Graphs are generated by solving and plotting the solution to a system of differential equations modeling harmonic oscillation over time.

Uploaded by

Hoklay Leng
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Homework: Answer

The document contains the solutions to multiple homework exercises involving matrix operations in MATLAB. It includes the code used to perform operations like matrix multiplication, addition, subtraction, transposition, and determining the inverse, determinant, eigenvalues and eigenvectors of matrices. Graphs are generated by solving and plotting the solution to a system of differential equations modeling harmonic oscillation over time.

Uploaded by

Hoklay Leng
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

LENG hoklay

ID: e20130359

Homework

Answer:
Exercise 1:
o By table 1
Row Vector

Column vector

Matrix

Block augmentation
Exercise 1:

Answer:

o By table 1
Row Vector

Pick
up row
vector

Column vector

M
atr
ix

Block augmentation

Pick up block matrix

Pick up column vector

Delete row
vector

Delete column vector

o By table1

Zeros (n) and Zeros (n,


m)

Ones (n) and One(n,m)

Eye(n) and Eye (n, m)

Answer exercise 2
M file
A=[3 4 5
0 2 3
0 0 1]
B=[1 2 3
4 5 6
7 8 9]
C=4
% Scalar multiplication
C*A
A*C
% Transporse
A'
% Matrix addition, substaction, multiplication
A+B
A-B
A*B
% Inverse
inv(A)
% Detarninant
det(A)
% Eigen value,eigen Vector
eig(A)
% Trace

trace(A)

% Rank

rank(A)
% Size of matrix
size(A)
% Summation of all elements
sum(A)
% Elementwise multiplication
C=A*B

Displays in cammand
12
0
0
A=
3
0
0

>> Untitled
4
2
0

5
3
1

A=

2
5
8

3
6
9

B=

B=
1
4
7
C=
4

ans =

3
0
0

1
4
7

4
2
0

5
3
1

2
5
8

3
6
9

C=
4

ans =
12
0
0

16 20
8 12
0 4

16 20
8 12
0 4

ans =
12
0
0

16 20
8 12
0 4

0
2
3

0
0
1

6
7
8

8
9
10

2
-3
-8

2
-3
-8

ans =
12
0
0

16 20
8 12
0 4

ans =

0
2
3

ans =

3
4
5

ans =
3
4
5

0
0
1

>> Untitled

4
4
7

A=
ans =
3
0
0

4
2
0

5
3
1

2
-4
-7

B=
ans =
1
4
7

2
5
8

3
6
9

C=

A=
3
0
0

ans =
16 20
8 12
0 4

16 20
8 12

4
2
0

5
3
1

2
5
8

3
6
9

B=
1
4
7

ans =
12
0

66 78
34 39
8 9

>> Untitled

12
0
0

54
29
7

C=
ans =
4
ans =
12
0
0

16 20
8 12
0 4

16 20
8 12
0 4

0
2
3

0
0
1

6
7
8

8
9
10

ans =
2
-4
-7

2
-3
-8

2
-3
-8

ans =
54
29
7

4
2
0

5
3
1

1
4
7

2
5
8

3
6
9

C=

ans =
4
4
7

3
0
0
B=

ans =
3
4
5

>> Untitled
A=

ans =
12
0
0

0.3333 -0.6667
0.3333
0 0.5000
-1.5000
0
0 1.0000

66 78
34 39
8 9

4
ans =
12
0
0

16 20
8 12
0 4

ans =
12
0
0
ans =

16 20
8 12
0 4

3
4
5

0
2
3

0
0
1

6
7
8

8
9
10

2
-3
-8

2
-3
-8

4
2
0

5
3
1

2
5
8

3
6
9

B=
1
4
7

ans =
2
-4
-7

A=
3
0
0

ans =
4
4
7

>> Untitled

C=
4

ans =
54
29
7

66 78
34 39
8 9

ans =

0.3333 -0.6667
0.3333
0 0.5000
-1.5000
0
0 1.0000

ans =

ans =

ans =

12
0
0

16 20
8 12
0 4

ans =

12
0
0

3
4
5

16 20
8 12
0 4

0
2
3

0
0
1

6
7

8
9

ans =
3
2
1

ans =
4
4

10
ans =

ans =
3
2
-4
-7

2
-3
-8

2
-3
-8

ans =
3

ans =
54
29
7

66 78
34 39
8 9

C=
54
29
7

66 78
34 39
8 9

ans =
>> Untitled
0.3333 -0.6667
0.3333
0 0.5000
-1.5000
0
0 1.0000
ans =
6
ans =
3
2
1
ans =
6
ans =
3

A=
3
0
0

4
2
0

5
3
1

2
5
8

3
6
9

B=
1
4
7
C=
4
ans =
12
0
0

16 20
8 12
0 4

ans =
12
0
0

6
16 20
8 12
0 4

ans =
3
2
1

ans =
3
4
5

0
2
3

0
0
1

ans =
6

ans =
ans =
4
4
7

6
7
8

8
9
10

3
ans =

ans =
3
2
-4
-7

2
-3
-8

2
-3
-8

ans =
3

ans =
54
29
7

66 78
34 39
8 9

C=
54
29
7

ans =
>>
0.3333 -0.6667
0.3333
0 0.5000
-1.5000
0
0 1.0000
ans =

66 78
34 39
8 9

Answer exercise3
mfile

A1=[0 1
-2 3]
A2=[1 0 1
1 0 2]
A3=[0 1 0
0 0 1
-1 -3 -3 ]
A2*A3
M=[A1
A2
Zeros(3,2) A3]
C=Eig (M)

Display
A1
-2
0

-2

-5

-6

-2

M=

A2 =

-1

-3

-3

A3 =
C=
0

1.0000 + 0.0000i

-1

-3

-3

2.0000 + 0.0000i
-1.0000 + 0.0000i

ans =

-1.0000 - 0.0000i
-1.0000 + 0.0000i

-1

-2

-3

Answer exercise 4

M file for function :

Not enougn input arguments.


Error in function
U=G* sin ( omega*t);
Mfile

clc;
global omega G
omega =0;
G=0;
[t,x]=ode45('f',[0.0 10.0],[1;1;0;0]);
figure(1);
plot(t,x(:,1),'-');
xlabel('time[sec]');
ylabel('x1');
figure(2);
plot(x(:,1),x(:,3),'*');
grid on;
Ploting figure:

You might also like