You are on page 1of 14

% % function

norank=("MAS3114_Project0")

norank =
"MAS3114_Project0"

A=[1,2,3,4,5,6,7,8,9,10,11,12]

A = 1×12
1 2 3 4 5 6 7 8 9 10 11 12

[m,n]=size(A)

m = 1
n = 12

fprintf('A is %i by %i matrix\n',m,n)

A is 1 by 12 matrix

R=[1,2,3,4,5,6,7,8,9,10,11,12]

R = 1×12
1 2 3 4 5 6 7 8 9 10 11 12

Pivort=1

Pivort = 1

% METHOD1
disp('check the code method1')

check the code method1

disp('the reduced echelon form of [A b] is')

the reduced echelon form of [A b] is

R = 1×12
1 2 3 4 5 6 7 8 9 10 11 12

disp('a solution of the system is')

a solution of the system is

x=[3,5,7,9]

x = 1×4
3 5 7 9

%(a)
A1=eye(5)

A1 = 5×5
1 0 0 0 0

1
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1

% if isequal(test1,test2,0)
b1=rand(5,0)

b1 =

5×0 empty double matrix

% if isequal(test1,test2,0)
disp('the system is inconsistent')

the system is inconsistent

%(b)
A2=magic(4)

A2 = 4×4
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1

% if isequal(test1,test2,0)
b2=rand(4,0)

b2 =

4×0 empty double matrix

% if isequal(test1,test2,0)
disp('the system is inconsistent')

the system is inconsistent

%(c)
A3=[magic(5),randi(10,5,0)]

A3 = 5×5
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9

% if isequal(test1,test2,0)
b3=rand(5,0)

b3 =

5×0 empty double matrix

% if isequal(test1,test2,0)
disp('the system is inconsistent')

2
the system is inconsistent

%(c)
A4=magic(5)

A4 = 5×5
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9

% if isequal(test1,test2,0)
b4=rand(5,0)

b4 =

5×0 empty double matrix

% if isequal(test1,test2,0)
disp('the system is inconsistent')

the system is inconsistent

%(d)
A5=[magic(5);zeros(2,5)]

A5 = 7×5
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
0 0 0 0 0
0 0 0 0 0

% if isequal(test1,test2,0)
b5=[rand(5,0);zeros(2,0)]

b5 =

7×0 empty double matrix

% if isequal(test1,test2,0)
disp('the system is inconsistent')

the system is inconsistent

%(e)
A6=[magic(5);randi(10,2,5)]

A6 = 7×5
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9

3
3 3 3 4 3
9 9 10 2 7

% if isequal(test1,test2,1)
b6=rand(7,1)

b6 = 7×1
0.4733
0.3517
0.8308
0.5853
0.5497
0.9172
0.2858

% if isequal(test1,test2,1)
disp('the system is inconsistent')

the system is inconsistent

%(f)
A7=randi([-5 5],5,3)

A7 = 5×3
3 -5 1
3 0 0
-1 3 -5
1 5 -2
-5 -4 -4

% if isequal(test1,test2,1)
b7=sum(A,2)

b7 = 78

% if isequal(test1,test2,1)
disp('the system is inconsistent')

the system is inconsistent

disp('the methods disagree - something is not quite right!')

the methods disagree - something is not quite right!

% METHOD2
disp('check the code method2')

check the code method2

disp('the t methods disagree - something is quite right!')

the t methods disagree - something is quite right!

Pivort

Pivort = 1

4
disp('a solution of the system is')

a solution of the system is

x=[-2,-4,-6]

x = 1×3
-2 -4 -6

%(a)
A8=eye(5,1)

A8 = 5×1
1
0
0
0
0

% if isequal(test1,test2,1)
b8=rand(5,1)

b8 = 5×1
0.7943
0.3112
0.5285
0.1656
0.6020

% if isequal(test1,test2,1)
disp('the system is consistent')

the system is consistent

%(b)
A9=magic(4)

A9 = 4×4
16 2 3 13
5 11 10 8
9 7 6 12
4 14 15 1

% if isequal(test1,test2,1)
b9=rand(4)

b9 = 4×4
0.2630 0.4505 0.1524 0.0782
0.6541 0.0838 0.8258 0.4427
0.6892 0.2290 0.5383 0.1067
0.7482 0.9133 0.9961 0.9619

% if isequal(test1,test2,1)
disp('the system is consistent')

the system is consistent

%(c)

5
A10=[magic(5),randi(10,5)]

A10 = 5×10
17 24 1 8 15 1 4 2 6 4
23 5 7 14 16 8 3 3 6 6
4 6 13 20 22 9 9 2 2 5
10 12 19 21 3 9 5 2 9 1
11 18 25 2 9 1 10 9 7 3

% if isequal(test1,test2,1)
b10=rand(10,5)

b10 = 10×5
0.1233 0.9001 0.9561 0.7317 0.6256
0.1839 0.3692 0.5752 0.6477 0.7802
0.2400 0.1112 0.0598 0.4509 0.0811
0.4173 0.7803 0.2348 0.5470 0.9294
0.0497 0.3897 0.3532 0.2963 0.7757
0.9027 0.2417 0.8212 0.7447 0.4868
0.9448 0.4039 0.0154 0.1890 0.4359
0.4909 0.0965 0.0430 0.6868 0.4468
0.4893 0.1320 0.1690 0.1835 0.3063
0.3377 0.9421 0.6491 0.3685 0.5085

% if isequal(test1,test2,1)
disp('the system is consistent')

the system is consistent

%(c)
A11=magic(5)

A11 = 5×5
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9

% if isequal(test1,test2,1)
b11=rand(5)

b11 = 5×5
0.5108 0.8116 0.5502 0.4709 0.1707
0.8176 0.5328 0.6225 0.2305 0.2277
0.7948 0.3507 0.5870 0.8443 0.4357
0.6443 0.9390 0.2077 0.1948 0.3111
0.3786 0.8759 0.3012 0.2259 0.9234

% if isequal(test1,test2,1)
disp('the system is consistent')

the system is consistent

%(d)
A12=[magic(5);zeros(2,5)]

A12 = 7×5
17 24 1 8 15

6
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
0 0 0 0 0
0 0 0 0 0

% if isequal(test1,test2,1)
b12=[rand(5,1);zeros(2,1)]

b12 = 7×1
0.4302
0.1848
0.9049
0.9797
0.4389
0
0

% if isequal(test1,test2,1)
disp('the system is consistent')

the system is consistent

%(e)
A13=[magic(5);randi(10,2,5)]

A13 = 7×5
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
2 5 3 8 2
3 6 7 3 3

% if isequal(test1,test2,1)
b13=rand(7)

b13 = 7×7
0.3188 0.9289 0.5468 0.3674 0.2619 0.4942 0.1978
0.4242 0.7303 0.5211 0.9880 0.3354 0.7791 0.0305
0.5079 0.4886 0.2316 0.0377 0.6797 0.7150 0.7441
0.0855 0.5785 0.4889 0.8852 0.1366 0.9037 0.5000
0.2625 0.2373 0.6241 0.9133 0.7212 0.8909 0.4799
0.8010 0.4588 0.6791 0.7962 0.1068 0.3342 0.9047
0.0292 0.9631 0.3955 0.0987 0.6538 0.6987 0.6099

% if isequal(test1,test2,1)
disp('the system is consistent')

the system is consistent

%(f)
A14=randi([-5 5],5,3)

A14 = 5×3
1 -3 5
4 4 2

7
3 -5 0
1 0 0
-3 -4 -5

% if isequal(test1,test2,1)
b14=sum(A,2)

b14 = 78

% if isequal(test1,test2,1)
disp('the system is consistent')

the system is consistent

disp('the vector of indexes of the pivot columns of [A b] is')

the vector of indexes of the pivot columns of [A b] is

% Figure:
plot(A)

plot(A1,'DisplayName','A1')

8
plot(A2,'DisplayName','A2')

9
plot(A3,'DisplayName','A3')

plot(A4,'DisplayName','A4')

10
plot(A5,'DisplayName','A5')

11
plot(A6,'DisplayName','A6')

plot(A7,'DisplayName','A7')

12
plot(b1)
plot(b2)
plot(b3)
plot(b4)
plot(b5)
plot(b6)

13
plot(R)

14

You might also like