Вы находитесь на странице: 1из 14

System of Linear Equations:

Homogenous with many solutions:

clc;
clear all;
close all;
syms x y z
eqn1 = x+y-z ==0;
eqn2 = y+2*z ==0;
eqn3 = x+2*y+z ==0;
[A,B] = equationsToMatrix([eqn1,eqn2,eqn3],[x,y,z])
X = linsolve(A,B)

Output:

A=

[ 1, 1, -1]
[ 0, 1, 2]
[ 1, 2, 1]

B=

0
0
0

Warning: Solution is not unique because the system is rank-deficient.


> In symengine
In sym/privBinaryOp (line 991)
In sym/linsolve (line 63)
In inverse1 (line 9)

X=

0
0
0
Homogenous equations with trivial solution:

clc;
clear all;
close all;
syms x y z
eqn1 = 3*x+z ==0;
eqn2 = 3*x+2*y+z==0;
eqn3 = 2*x+2*y+2*z ==0;
[A,B] = equationsToMatrix([eqn1,eqn2,eqn3],[x,y,z])
X = linsolve(A,B)

Output:

A=

[ 3, 0, 1]
[ 3, 2, 1]
[ 2, 2, 2]

B=

0
0
0

X=

0
0
0
Non Homogenous with unique solution:

clc;
clear all;
close all;
syms x y z
eqn1 = x+y+z ==10000;
eqn2 = 0.1*x+0.07*y+0.05*z ==800;
eqn3 = x-y-z ==0;
[A,B] = equationsToMatrix([eqn1,eqn2,eqn3],[x,y,z])
X = linsolve(A,B)

Output:

A=

[ 1, 1, 1]
[ 1/10, 7/100, 1/20]
[ 1, -1, -1]

B=

10000
800
0

X=

5000
2500
2500
Non Homogenous equations with no solution:

clc;
clear all;
close all;
syms x y z
eqn1 = x+2*y+z == 8;
eqn2 = 2*x+2*y+2*z ==13;
eqn3 = 3*x+4*y+3*z ==5;
[A,B] = equationsToMatrix([eqn1,eqn2,eqn3],[x,y,z])
X = linsolve(A,B)

Output:

A=

[ 1, 2, 1]
[ 2, 2, 2]
[ 3, 4, 3]

B=

8
13
5

Warning: Solution does not exist because the system is inconsistent.


> In symengine
In sym/privBinaryOp (line 991)
In sym/linsolve (line 63)
In syseqNonHomo2 (line 9)

X=

Inf
Inf
Inf
Non Homogenous equations with infinitely many solutions:

clc;
clear all;
close all;
syms x y z
eqn1 = x+2*y+z == 8;
eqn2 = 2*x+2*y+2*z ==13;
eqn3 = 3*x+4*y+3*z ==21;
[A,B] = equationsToMatrix([eqn1,eqn2,eqn3],[x,y,z])
X = linsolve(A,B)

Output:

A=

[ 1, 2, 1]
[ 2, 2, 2]
[ 3, 4, 3]

B=

8
13
21

Warning: Solution is not unique because the system is rank-deficient.


> In symengine
In sym/privBinaryOp (line 991)
In sym/linsolve (line 63)
In syseqNonHomo2 (line 9)

X=

5
3/2
0
Linearly dependent and Independent Vectors:

1.
clc;
clear all;
close all;
A=

1 0 0
0 1 0
0 0 1
rank(A)

Output:

A=

1 0 0
0 1 0
0 0 1

ans = 3

The given set of vectors are linearly independent

2.
clc;
clear all;
close all;
A=

2 5 3
1 1 1
4 -2 0
rank(A)

Output:

A=
2 5 3
1 1 1
4 -2 0
ans = 3
The given set of vectors are linearly independent
3.
clc;
clear all;
close all;
A=
1 2 0
1 1 1
0 -1 2
rank(A)

Output:

A=

1 2 0
1 1 1
0 -1 2

ans = 3

The given set of vectors are linearly independent

4.
clc;
clear all;
close all;
A=

1 2 0
1 1 1
0 -1 1
rank(A)

Output:

A=

1 2 0
1 1 1
0 -1 1

ans = 3

The given set of vectors are linearly dependent


5.
clc;
clear all;
close all;
A=

1 2 0
1 1 1
0 -1 2
rank(A)

Output:

A=

3 4 5
-3 0 5
4 4 4
3 4 0

ans = 3

The given set of vectors are linearly dependent


Inverse matrix

1.
clc;
clear all;
close all;

A= ;

B=inv(A);

Output:

B=
0.118644067796610 -0.101694915254237 0.135593220338983
-0.779661016949152 0.525423728813559 -0.0338983050847458
0.491525423728813 -0.135593220338983 -0.152542372881356

2.
clc;
clear all;
close all;

A= ;

B=inv(A);

Output:

B=
-4.50359962737050e+15 9.00719925474099e+15 -4.50359962737050e+15
9.00719925474100e+15 -1.80143985094820e+16 9.00719925474099e+15
-4.50359962737050e+15 9.00719925474099e+15 -4.50359962737050e+15
3.
clc;
clear all;
close all;

A= ;

B=inv(A);

Output:

B=
0 1 -1
0.500000000000000 -0.500000000000000 0.500000000000000
0 -1 2

4.
clc;
clear all;
close all;

A= ;

B=inv(A);

Output:

B=
1 0 0
0 1 0
0 0 1
5.
clc;
clear all;
close all;

A= ;

B=inv(A);

Output:

B=
-0.111111111111111 0 0.222222222222222
-4.44444444444445 1 0.888888888888889
0.555555555555556 0 -0.111111111111111
Transpose:

1.
clc;
clear all;
close all;

A= ;

B=A’;

Output:

B=
1 0 5
0 1 0
2 8 1

2.
clc;
clear all;
close all;

A= ;

B=A’;

Output:

B=
1 0 0
0 1 0
0 0 1
3.
clc;
clear all;
close all;

A= ;

B=A’;

Output:

B=
5 8 9
2 5 2
4 6 1

4.
clc;
clear all;
close all;

A= ;

B=A’;

Output:

B=
1 4 7
2 5 8
3 6 9
5.
clc;
clear all;
close all;

A= ;

B=A’;

Output:

B=
1 2 1
2 0 0
0 1 1

Вам также может понравиться