Skip to content

Commit 26addb8

Browse files
committed
Adding an example for Sage 😈
1 parent de17fe2 commit 26addb8

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

examples/example.sage

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
def isinverse(matrix):
2+
"""
3+
This function checks if a matrix has an inverse and if it does it outputs it, if not returns FALSE.
4+
5+
arguements: A matrix
6+
7+
outputs: if inverse exists - the invese of the matrix
8+
inverse doesn't exist - this matrix has no inverse
9+
"""
10+
11+
try:
12+
return matrix.inverse()
13+
except:
14+
return "This matrix has no inverse"
15+
16+
C = matrix([[-1/2, -1/2], [-2, -1]])
17+
print isinverse(C)
18+
print "The determinant of this matrix is:"
19+
print det(C)
20+
21+
D = matrix([[2, -2, 1], [6, -1, 1], [12, -2, 2]])
22+
print isinverse(D)
23+
print "The determinant of this matrix is:"
24+
print det(D)
25+
26+
E = matrix([[1, 2], [2, 0]])
27+
print isinverse(E)
28+
print "The determinant of this matrix is:"
29+
print det(E)

0 commit comments

Comments
 (0)