-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSAMPLES.txt
More file actions
203 lines (179 loc) · 4.67 KB
/
Copy pathSAMPLES.txt
File metadata and controls
203 lines (179 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
Here some help and samples about the Py_Matrix Module.
======================================================
------------
| SAMPLES: |
------------
0) Import the module:
---------------------
>>> import Py_Matrix as py_m
1) Create a Matrix from a dataset:
----------------------------------
>>> A = py_m.Matrix([1,2,3,4], 2, 2)
2) Print a Matrix:
------------------
>>> print(A) #A previously declared
Output:
0| 1 2
1| 3 4
-- --
0 1
3) Print an element of the matrix, knowing row and column:
----------------------------------------------------------
WARNING: the first row is number 0, same as first column. It does not starts with 1
>>> print(A.elem(1,0) #A previously declared
Output: 3
4) Add two Matrix (Matrix + Matrix):
------------------------------------
WARNING: Matrix must have same rows and columns
>>> A = py_m.Matrix([1,2,3,4], 2, 2)
>>> B = py_m.Matrix([4,3,2,1], 2, 2)
>>> print(A+B)
Output:
0| 5 5
1| 5 5
-- --
0 1
5) Matrix * Matrix:
-------------------
WARNING: Matrix multiplication is not commutative
>>>print(A*B) #A and B previously declared
Output:
0| 8 5
1| 20 13
-- --
0 1
6) Matrix * number:
-------------------
WARNING: 2*A is not implemented.
>>> print(A*2) #A and B previously declared
Output:
0| 2 4
1| 6 8
-- --
0 1
7) Transpose of a Matrix:
-------------------------
>>> print(A.t()) #A previously declared
Output:
0| 1 3
1| 2 4
-- --
0 1
8) Elementary operation 3:
--------------------------
>>> A.elementary_op3(0,1,-3)
Then:
0| 1 2
1| 3+(1)*(-3) 4+(2)*(-3)
-- --
0 1
Output:
0| 1 2
1| 0 -2
-- --
0 1
9) Submatrix of a matrix:
-------------------------
>>> print(A.sub(0,0)) #A previously declared
Output:
0| 4
--
0
10) Determinant of a matrix (2 ways):
-------------------------------------
1)
>>> print(A.det)
#return a number
2)
>>> print(det_nxn(A))
Better to use 1) instead of 2)
11) Cofactor of a Matrix:
-------------------------
#deleting the element in (0,0)
>>> print(A.cofactor(0,0)) #A previously declared
Output: 4
12) Inverse Matrix:
-------------------
>>> print(A.inverse()) #A previously declared
Output:
0| -2.000 1.000
1| 1.500 -0.500
-- --
0 1
13) Cramer Rule on Linear System:
---------------------------------
>>> B = Matrix([4,3],2,1)
>>> print(cramer_rule(A,B)) #A previously declared
Output:
0| -5.000
1| 4.500
--
0
14) Matrix Infromations:
------------------------
>>> A.info() #A previously declared
15) Matrix Iteration:
---------------------
>>> for i in A: #A previously declared as Matrix([1,2,3,4],2,2)
print(i)
Output:
1
2
3
4
16) Lenght:
-----------
>>> print(len(A)) #A previously declared as Matrix([1,2,3,4],2,2)
Output:
4
17) Find Pivot:
---------------
>>> print(A) #A previously declared as Matrix([1,2,0,4],2,2)
Output:
0| 1 2
1| 0 4
-- --
0 1
>>> print(A.find_pivot(1))
Output:
4
18) Pivot List:
---------------
>>> A = py_m.Matrix([1,2,3,4], 2, 2)
>>> print(A.pivot_list())
Output:
[(0, 0, 1), (0, 1, 3)]
19) Sort a Matrix:
------------------
>>> A = py_m.Matrix([0,1,3,4], 2, 2)
>>> print(A.sort())
Output:
0| 3 4
1| 0 1
-- --
0 1
20) Gaussian Elimination:
-------------------------
>>> A = py_m.Matrix([0,1,3,4], 2, 2)
>>> print(A.gaussian_elimination())
Output:
0| 5 1 3
1| 0.000 2.600 -3.200
2| 0.000 0.000 -7.077
-- -- --
0 1 2
21) Characteristic Polynomial:
------------------------------
>>> A = py_m.Matrix([0,1,3,4], 2, 2)
>>> print(A.characteristic_polynomial())
Output:
'(((0+-x)*(4+-x)) + (-1)*((3+0)*(1+0)))'
22) Rotate a Matrix counterclockwise:
-------------------------------------
>>> A = py_m.Matrix([0,1,3,4], 2, 2)
>>> print(A.rotate())
Output:
0| 1 4
1| 0 3
-- --
0 1