typeset_mode(True) A=random_matrix(QQ,3,3)
A
2221−10−2102−1
A.echelon_form()
100010001
B=matrix(3,3,[1,2,3,0,2,3,0,0,3])
B
100220333
B.echelon_form()
100020003
A.rref()
100010001
B.rref()
100010001
M=block_matrix([[A,1]]) #A augmentée de Id
M M.echelon_form()
2221−10−2102−1100010001
100010001−1−3112−2124−2
A^-1
−1−3112−2124−2
var('r') P=matrix(3,3,[1,r,r**2,r,1,r,r**2,r,1])
r
P
1rr2r1rr2r1
P.echelon_form() P.rref() block_matrix([[P,1]]).echelon_form()
100010r2−r2−1(r3−r)r01
100010r2−r2−1(r3−r)r01
100010r2−r2−1(r3−r)r01−r2−1r2+1−(r4−r2−1(r3−r)2−1)(r2−1)(r3−r)(r2−r2−1(r3−r)r)+r2−1rr4−r2−1(r3−r)2−1r2−r2−1(r3−r)rr2−1r−(r4−r2−1(r3−r)2−1)(r2−1)2(r3−r)2−r2−11(r4−r2−1(r3−r)2−1)(r2−1)r3−r0(r4−r2−1(r3−r)2−1)(r2−1)r3−r−r4−r2−1(r3−r)2−11
P^-1
−r2−1r2+1−(r4−r2−1(r3−r)2−1)(r2−1)(r3−r)(r2−r2−1(r3−r)r)+r2−1rr4−r2−1(r3−r)2−1r2−r2−1(r3−r)rr2−1r−(r4−r2−1(r3−r)2−1)(r2−1)2(r3−r)2−r2−11(r4−r2−1(r3−r)2−1)(r2−1)r3−r0(r4−r2−1(r3−r)2−1)(r2−1)r3−r−r4−r2−1(r3−r)2−11
#Exercice 2 u=vector([1,0]) v=vector([0,2]) u v
(1,0)
(0,2)
plot(u)+plot(v)
plot(u)+plot(v)+plot(u*matrix(2,2,[0,-1,-1,0]),color='green')+plot(v*matrix(2,2,[0,-1,-1,0]),color='green')+plot(u*matrix(2,2,[1,1,-1,1]),color='red')+plot(v*matrix(2,2,[1,1,-1,1]),color='red')+plot(u*matrix(2,2,[1,0,1,1]),color='orange')+plot(v*matrix(2,2,[1,0,1,1]),color='orange')+plot(u*matrix(2,2,[3,0,0,3]),color='purple')+plot(v*matrix(2,2,[3,0,0,3]),color='purple')+plot(u*matrix(2,2,[0,0,0,1]),color='black')+plot(v*matrix(2,2,[0,0,0,1]),color='black')+plot(u*matrix(2,2,[2,1,1,0]),color='teal')+plot(v*matrix(2,2,[2,1,1,0]),color='teal')+plot(u*matrix(2,2,[1,1,-3,0]),color='brown')+plot(v*matrix(2,2,[1,1,-3,0]),color='brown')+plot(u*matrix(2,2,[2,-1,1,2]),color='pink')+plot(v*matrix(2,2,[2,-1,1,2]),color='pink')+plot(u*matrix(2,2,[0,0,1,0]),color='yellow')+plot(v*matrix(2,2,[0,0,1,0]),color='yellow')
#Exercice 3 A=matrix(3,3,[1,1/2,1/3,1/2,1/3,1/4,1/3,1/4,1/5])
A
12131213141314151
B=matrix(3,3,[1,0.5,0.33,0.5,0.33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333,0.25,0.333333333333333333333333333333333333333333333333333333333333333333333333333333333333,0.25,0.20]) #mettre bcp de 3...
B
1.000000000000000.5000000000000000.3333333333333330.5000000000000000.3333333333333330.2500000000000000.3300000000000000.2500000000000000.200000000000000
A^-1 B^-1
9−3630−36192−18030−180180
10.0000000000000−40.000000000000233.3333333333335−42.0000000000002216.000000000001−200.00000000000136.0000000000002−204.000000000001200.000000000001
block_matrix([[B,1]]).echelon_form()
1.000000000000000.0000000000000000.0000000000000000.0000000000000001.000000000000000.0000000000000000.0000000000000000.0000000000000001.0000000000000055.5555555555539−277.777777777769255.555555555548−277.7777777777691446.03174603170−1349.20634920631255.555555555548−1349.206349206311269.84126984123
#Exercice 4
var('a b c d e f g h i') D=matrix(3,3,[a,b,c,d,e,f,g,h,i]) D
(a, b, c, d, e, f, g, h, i)
adgbehcfi
timeit('D.det()')
625 loops, best of 3: 1.36 µs per loop
def sarrus(a,b,c,d,e,f,g,h,i): X=(a*e*i+b*f*g+c*d*h)-(g*e*c+h*f*a+i*d*b) return(X)
timeit('sarrus(a,b,c,d,e,f,g,h,i)')
625 loops, best of 3: 12.9 µs per loop
(625*12.9)*10^-6 (625*1.36)*10^-6
0.00806250000000000
0.000850000000000000