Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download
Project: MAO
Views: 41
typeset_mode(True) A=random_matrix(QQ,3,3)
A
(21020212121)\displaystyle \left(\begin{array}{rrr} 2 & -1 & 0 \\ 2 & 0 & 2 \\ \frac{1}{2} & -\frac{1}{2} & -1 \end{array}\right)
A.echelon_form()
(100010001)\displaystyle \left(\begin{array}{rrr} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{array}\right)
B=matrix(3,3,[1,2,3,0,2,3,0,0,3])
B
(123023003)\displaystyle \left(\begin{array}{rrr} 1 & 2 & 3 \\ 0 & 2 & 3 \\ 0 & 0 & 3 \end{array}\right)
B.echelon_form()
(100020003)\displaystyle \left(\begin{array}{rrr} 1 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & 3 \end{array}\right)
A.rref()
(100010001)\displaystyle \left(\begin{array}{rrr} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{array}\right)
B.rref()
(100010001)\displaystyle \left(\begin{array}{rrr} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{array}\right)
M=block_matrix([[A,1]]) #A augmentée de Id
M M.echelon_form()
(21010020201012121001)\displaystyle \left(\begin{array}{rrr|rrr} 2 & -1 & 0 & 1 & 0 & 0 \\ 2 & 0 & 2 & 0 & 1 & 0 \\ \frac{1}{2} & -\frac{1}{2} & -1 & 0 & 0 & 1 \end{array}\right)
(1001120103240011122)\displaystyle \left(\begin{array}{rrr|rrr} 1 & 0 & 0 & -1 & 1 & 2 \\ 0 & 1 & 0 & -3 & 2 & 4 \\ 0 & 0 & 1 & 1 & -\frac{1}{2} & -2 \end{array}\right)
A^-1
(1123241122)\displaystyle \left(\begin{array}{rrr} -1 & 1 & 2 \\ -3 & 2 & 4 \\ 1 & -\frac{1}{2} & -2 \end{array}\right)
var('r') P=matrix(3,3,[1,r,r**2,r,1,r,r**2,r,1])
r\displaystyle r
P
(1rr2r1rr2r1)\displaystyle \left(\begin{array}{rrr} 1 & r & r^{2} \\ r & 1 & r \\ r^{2} & r & 1 \end{array}\right)
P.echelon_form() P.rref() block_matrix([[P,1]]).echelon_form()
(10r2(r3r)rr21010001)\displaystyle \left(\begin{array}{rrr} 1 & 0 & r^{2} - \frac{{\left(r^{3} - r\right)} r}{r^{2} - 1} \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{array}\right)
(10r2(r3r)rr21010001)\displaystyle \left(\begin{array}{rrr} 1 & 0 & r^{2} - \frac{{\left(r^{3} - r\right)} r}{r^{2} - 1} \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{array}\right)
(10r2(r3r)rr21r2r21+1rr210010(r3r)(r2(r3r)rr21)(r4(r3r)2r211)(r21)+rr21(r3r)2(r4(r3r)2r211)(r21)21r21r3r(r4(r3r)2r211)(r21)001r2(r3r)rr21r4(r3r)2r211r3r(r4(r3r)2r211)(r21)1r4(r3r)2r211)\displaystyle \left(\begin{array}{rrr|rrr} 1 & 0 & r^{2} - \frac{{\left(r^{3} - r\right)} r}{r^{2} - 1} & -\frac{r^{2}}{r^{2} - 1} + 1 & \frac{r}{r^{2} - 1} & 0 \\ 0 & 1 & 0 & -\frac{{\left(r^{3} - r\right)} {\left(r^{2} - \frac{{\left(r^{3} - r\right)} r}{r^{2} - 1}\right)}}{{\left(r^{4} - \frac{{\left(r^{3} - r\right)}^{2}}{r^{2} - 1} - 1\right)} {\left(r^{2} - 1\right)}} + \frac{r}{r^{2} - 1} & -\frac{{\left(r^{3} - r\right)}^{2}}{{\left(r^{4} - \frac{{\left(r^{3} - r\right)}^{2}}{r^{2} - 1} - 1\right)} {\left(r^{2} - 1\right)}^{2}} - \frac{1}{r^{2} - 1} & \frac{r^{3} - r}{{\left(r^{4} - \frac{{\left(r^{3} - r\right)}^{2}}{r^{2} - 1} - 1\right)} {\left(r^{2} - 1\right)}} \\ 0 & 0 & 1 & \frac{r^{2} - \frac{{\left(r^{3} - r\right)} r}{r^{2} - 1}}{r^{4} - \frac{{\left(r^{3} - r\right)}^{2}}{r^{2} - 1} - 1} & \frac{r^{3} - r}{{\left(r^{4} - \frac{{\left(r^{3} - r\right)}^{2}}{r^{2} - 1} - 1\right)} {\left(r^{2} - 1\right)}} & -\frac{1}{r^{4} - \frac{{\left(r^{3} - r\right)}^{2}}{r^{2} - 1} - 1} \end{array}\right)
P^-1
(r2r21+1rr210(r3r)(r2(r3r)rr21)(r4(r3r)2r211)(r21)+rr21(r3r)2(r4(r3r)2r211)(r21)21r21r3r(r4(r3r)2r211)(r21)r2(r3r)rr21r4(r3r)2r211r3r(r4(r3r)2r211)(r21)1r4(r3r)2r211)\displaystyle \left(\begin{array}{rrr} -\frac{r^{2}}{r^{2} - 1} + 1 & \frac{r}{r^{2} - 1} & 0 \\ -\frac{{\left(r^{3} - r\right)} {\left(r^{2} - \frac{{\left(r^{3} - r\right)} r}{r^{2} - 1}\right)}}{{\left(r^{4} - \frac{{\left(r^{3} - r\right)}^{2}}{r^{2} - 1} - 1\right)} {\left(r^{2} - 1\right)}} + \frac{r}{r^{2} - 1} & -\frac{{\left(r^{3} - r\right)}^{2}}{{\left(r^{4} - \frac{{\left(r^{3} - r\right)}^{2}}{r^{2} - 1} - 1\right)} {\left(r^{2} - 1\right)}^{2}} - \frac{1}{r^{2} - 1} & \frac{r^{3} - r}{{\left(r^{4} - \frac{{\left(r^{3} - r\right)}^{2}}{r^{2} - 1} - 1\right)} {\left(r^{2} - 1\right)}} \\ \frac{r^{2} - \frac{{\left(r^{3} - r\right)} r}{r^{2} - 1}}{r^{4} - \frac{{\left(r^{3} - r\right)}^{2}}{r^{2} - 1} - 1} & \frac{r^{3} - r}{{\left(r^{4} - \frac{{\left(r^{3} - r\right)}^{2}}{r^{2} - 1} - 1\right)} {\left(r^{2} - 1\right)}} & -\frac{1}{r^{4} - \frac{{\left(r^{3} - r\right)}^{2}}{r^{2} - 1} - 1} \end{array}\right)
#Exercice 2 u=vector([1,0]) v=vector([0,2]) u v
(1,0)\displaystyle \left(1,\,0\right)
(0,2)\displaystyle \left(0,\,2\right)
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
(11213121314131415)\displaystyle \left(\begin{array}{rrr} 1 & \frac{1}{2} & \frac{1}{3} \\ \frac{1}{2} & \frac{1}{3} & \frac{1}{4} \\ \frac{1}{3} & \frac{1}{4} & \frac{1}{5} \end{array}\right)
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.3300000000000000.5000000000000000.3333333333333330.2500000000000000.3333333333333330.2500000000000000.200000000000000)\displaystyle \left(\begin{array}{rrr} 1.00000000000000 & 0.500000000000000 & 0.330000000000000 \\ 0.500000000000000 & 0.333333333333333 & 0.250000000000000 \\ 0.333333333333333 & 0.250000000000000 & 0.200000000000000 \end{array}\right)
A^-1 B^-1
(936303619218030180180)\displaystyle \left(\begin{array}{rrr} 9 & -36 & 30 \\ -36 & 192 & -180 \\ 30 & -180 & 180 \end{array}\right)
(10.000000000000042.000000000000236.000000000000240.0000000000002216.000000000001204.00000000000133.3333333333335200.000000000001200.000000000001)\displaystyle \left(\begin{array}{rrr} 10.0000000000000 & -42.0000000000002 & 36.0000000000002 \\ -40.0000000000002 & 216.000000000001 & -204.000000000001 \\ 33.3333333333335 & -200.000000000001 & 200.000000000001 \end{array}\right)
block_matrix([[B,1]]).echelon_form()
(1.000000000000000.0000000000000000.00000000000000055.5555555555539277.777777777769255.5555555555480.0000000000000001.000000000000000.000000000000000277.7777777777691446.031746031701349.206349206310.0000000000000000.0000000000000001.00000000000000255.5555555555481349.206349206311269.84126984123)\displaystyle \left(\begin{array}{rrr|rrr} 1.00000000000000 & 0.000000000000000 & 0.000000000000000 & 55.5555555555539 & -277.777777777769 & 255.555555555548 \\ 0.000000000000000 & 1.00000000000000 & 0.000000000000000 & -277.777777777769 & 1446.03174603170 & -1349.20634920631 \\ 0.000000000000000 & 0.000000000000000 & 1.00000000000000 & 255.555555555548 & -1349.20634920631 & 1269.84126984123 \end{array}\right)
#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\displaystyle a, b\displaystyle b, c\displaystyle c, d\displaystyle d, e\displaystyle e, f\displaystyle f, g\displaystyle g, h\displaystyle h, i\displaystyle i)
(abcdefghi)\displaystyle \left(\begin{array}{rrr} a & b & c \\ d & e & f \\ g & h & i \end{array}\right)
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\displaystyle 0.00806250000000000
0.000850000000000000\displaystyle 0.000850000000000000