Matriz inversa y pseudoinversa

parent be0f1d49
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 159, "execution_count": 1,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
" [10, 11, 12, 13, 14]], dtype=int16)" " [10, 11, 12, 13, 14]], dtype=int16)"
] ]
}, },
"execution_count": 159, "execution_count": 1,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -868,7 +868,7 @@ ...@@ -868,7 +868,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 2,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -949,16 +949,16 @@ ...@@ -949,16 +949,16 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 173, "execution_count": 1233,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"'def matmult(a,b):\\n zip_b = zip(*b)\\n #uncomment next line if python 3 : \\n zip_b = list(zip_b)\\n return [[sum(ele_a*ele_b for ele_a, ele_b in zip(row_a, col_b)) \\n for col_b in zip_b] for row_a in a]\\n'" "'b=mat2\\nprint(b)\\nzip_b = zip(*b)\\nfor col_b in zip_b:\\n print(col_b)\\n'"
] ]
}, },
"execution_count": 173, "execution_count": 1233,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -1024,7 +1024,7 @@ ...@@ -1024,7 +1024,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 118, "execution_count": 1243,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -1034,7 +1034,7 @@ ...@@ -1034,7 +1034,7 @@
"Ingrese las filas de la matriz: \n", "Ingrese las filas de la matriz: \n",
"2\n", "2\n",
"Ingrese las columnas de la matriz: \n", "Ingrese las columnas de la matriz: \n",
"3\n" "2\n"
] ]
} }
], ],
...@@ -1044,7 +1044,7 @@ ...@@ -1044,7 +1044,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 133, "execution_count": 782,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -1054,7 +1054,7 @@ ...@@ -1054,7 +1054,7 @@
"Ingrese las filas de la matriz: \n", "Ingrese las filas de la matriz: \n",
"3\n", "3\n",
"Ingrese las columnas de la matriz: \n", "Ingrese las columnas de la matriz: \n",
"2\n" "3\n"
] ]
} }
], ],
...@@ -1064,7 +1064,71 @@ ...@@ -1064,7 +1064,71 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 119, "execution_count": 1095,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ingrese las filas de la matriz: \n",
"2\n",
"Ingrese las columnas de la matriz: \n",
"3\n"
]
}
],
"source": [
"cc=tamMatriz()"
]
},
{
"cell_type": "code",
"execution_count": 1236,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ingrese las filas de la matriz: \n",
"5\n",
"Ingrese las columnas de la matriz: \n",
"5\n"
]
}
],
"source": [
"dd=tamMatriz()"
]
},
{
"cell_type": "code",
"execution_count": 1393,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ingresa el valor del elemento0,0: \n",
"1400\n",
"Ingresa el valor del elemento0,1: \n",
"970\n",
"Ingresa el valor del elemento1,0: \n",
"970\n",
"Ingresa el valor del elemento1,1: \n",
"878\n"
]
}
],
"source": [
"mat1 = creaMatriz(aa[0],aa[1])"
]
},
{
"cell_type": "code",
"execution_count": 784,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -1082,17 +1146,23 @@ ...@@ -1082,17 +1146,23 @@
"Ingresa el valor del elemento1,1: \n", "Ingresa el valor del elemento1,1: \n",
"5\n", "5\n",
"Ingresa el valor del elemento1,2: \n", "Ingresa el valor del elemento1,2: \n",
"6\n" "6\n",
"Ingresa el valor del elemento2,0: \n",
"7\n",
"Ingresa el valor del elemento2,1: \n",
"8\n",
"Ingresa el valor del elemento2,2: \n",
"10\n"
] ]
} }
], ],
"source": [ "source": [
"mat1 = creaMatriz(aa[0],aa[1])" "mat2=creaMatriz(bb[0],bb[1])"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 134, "execution_count": 1222,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -1103,24 +1173,90 @@ ...@@ -1103,24 +1173,90 @@
"10\n", "10\n",
"Ingresa el valor del elemento0,1: \n", "Ingresa el valor del elemento0,1: \n",
"20\n", "20\n",
"Ingresa el valor del elemento1,0: \n", "Ingresa el valor del elemento0,2: \n",
"30\n", "30\n",
"Ingresa el valor del elemento1,0: \n",
"18\n",
"Ingresa el valor del elemento1,1: \n", "Ingresa el valor del elemento1,1: \n",
"40\n", "5\n",
"Ingresa el valor del elemento1,2: \n",
"23\n"
]
}
],
"source": [
"mat3=creaMatriz(cc[0],cc[1])"
]
},
{
"cell_type": "code",
"execution_count": 1255,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Ingresa el valor del elemento0,0: \n",
"1\n",
"Ingresa el valor del elemento0,1: \n",
"1\n",
"Ingresa el valor del elemento0,2: \n",
"0\n",
"Ingresa el valor del elemento0,3: \n",
"2\n",
"Ingresa el valor del elemento0,4: \n",
"-1\n",
"Ingresa el valor del elemento1,0: \n",
"0\n",
"Ingresa el valor del elemento1,1: \n",
"0\n",
"Ingresa el valor del elemento1,2: \n",
"2\n",
"Ingresa el valor del elemento1,3: \n",
"-1\n",
"Ingresa el valor del elemento1,4: \n",
"2\n",
"Ingresa el valor del elemento2,0: \n", "Ingresa el valor del elemento2,0: \n",
"50\n", "0\n",
"Ingresa el valor del elemento2,1: \n", "Ingresa el valor del elemento2,1: \n",
"60\n" "2\n",
"Ingresa el valor del elemento2,2: \n",
"-3\n",
"Ingresa el valor del elemento2,3: \n",
"4\n",
"Ingresa el valor del elemento2,4: \n",
"5\n",
"Ingresa el valor del elemento3,0: \n",
"1\n",
"Ingresa el valor del elemento3,1: \n",
"0\n",
"Ingresa el valor del elemento3,2: \n",
"-1\n",
"Ingresa el valor del elemento3,3: \n",
"1\n",
"Ingresa el valor del elemento3,4: \n",
"1\n",
"Ingresa el valor del elemento4,0: \n",
"0\n",
"Ingresa el valor del elemento4,1: \n",
"0\n",
"Ingresa el valor del elemento4,2: \n",
"0\n",
"Ingresa el valor del elemento4,3: \n",
"0\n",
"Ingresa el valor del elemento4,4: \n",
"4\n"
] ]
} }
], ],
"source": [ "source": [
"mat2=creaMatriz(bb[0],bb[1])" "mat4=creaMatriz(dd[0],dd[1])"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 210, "execution_count": 10,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -1133,10 +1269,10 @@ ...@@ -1133,10 +1269,10 @@
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"[[220, 280], [490, 640]]" "[[500, 600], [1140, 1400]]"
] ]
}, },
"execution_count": 210, "execution_count": 10,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -1154,17 +1290,17 @@ ...@@ -1154,17 +1290,17 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 206, "execution_count": 11,
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"data": { "data": {
"text/plain": [ "text/plain": [
"array([[220, 280],\n", "array([[ 500, 600],\n",
" [490, 640]])" " [1140, 1400]])"
] ]
}, },
"execution_count": 206, "execution_count": 11,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -1176,6 +1312,100 @@ ...@@ -1176,6 +1312,100 @@
"np.matmul(mat1, mat2)" "np.matmul(mat1, mat2)"
] ]
}, },
{
"cell_type": "code",
"execution_count": 1414,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1. 0.69285714]\n"
]
}
],
"source": [
"x=np.array(mat1,dtype=np.float64)\n",
"y=np.array(mat2)\n",
"z=np.array(mat3,dtype=np.float64)\n",
"w=np.array(mat4,dtype=np.float64)\n",
"#A=np.array(mmult1(x,y))\n",
"#np.linalg.det(A)\n",
"#b = np.array([[ 0, 1, 2, 3, 4],\n",
"# [ 5, 6, 7, 8, 9],\n",
"# [10, 11, 12, 13, 14]], dtype=np.int16)\n",
"#b\n",
"\n",
"#Toda la fila x[0,:]\n",
"print(x[0,:]*1/1400)\n"
]
},
{
"cell_type": "code",
"execution_count": 1022,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[]\n",
"[1. 2. 3.]\n"
]
},
{
"data": {
"text/plain": [
"[20, 30]"
]
},
"execution_count": 1022,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Encontrar uno\n",
"xxx=[[1,2,3],[0,5,6],[7,8,9]]\n",
"xxx1=np.array(xxx)\n",
"\n",
"xxx1=np.append(xxx1,[10,20,30])\n",
"xxx1\n",
"\n",
"a = np.array([]).reshape(0,3)\n",
"print(a)\n",
"a=np.append(a,[1,2,3])\n",
"print(a)\n",
"\n",
"x[0,:]\n",
"lineas=[]\n",
"lineas.append([5,10])\n",
"lineas.append([20,30])\n",
"lineas[-1]"
]
},
{
"cell_type": "code",
"execution_count": 1403,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0.00304544, -0.00336455],\n",
" [-0.00336455, 0.00485605]])"
]
},
"execution_count": 1403,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.linalg.inv(x)"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
...@@ -1184,6 +1414,470 @@ ...@@ -1184,6 +1414,470 @@
"[Wikipedia](https://en.wikipedia.org/wiki/Gaussian_elimination): En matemáticas, la eliminación de Gauss Jordan, llamada así en honor de Carl Friedrich Gauss y Wilhelm Jordan es un algoritmo del álgebra lineal que se usa para determinar las soluciones de un sistema de ecuaciones lineales, para encontrar matrices e inversas. Un sistema de ecuaciones se resuelve por el método de Gauss cuando se obtienen sus soluciones mediante la reducción del sistema dado a otro equivalente en el que cada ecuación tiene una incógnita menos que la anterior. El método de Gauss transforma la matriz de coeficientes en una matriz triangular superior. El método de Gauss-Jordan continúa el proceso de transformación hasta obtener una matriz diagonal" "[Wikipedia](https://en.wikipedia.org/wiki/Gaussian_elimination): En matemáticas, la eliminación de Gauss Jordan, llamada así en honor de Carl Friedrich Gauss y Wilhelm Jordan es un algoritmo del álgebra lineal que se usa para determinar las soluciones de un sistema de ecuaciones lineales, para encontrar matrices e inversas. Un sistema de ecuaciones se resuelve por el método de Gauss cuando se obtienen sus soluciones mediante la reducción del sistema dado a otro equivalente en el que cada ecuación tiene una incógnita menos que la anterior. El método de Gauss transforma la matriz de coeficientes en una matriz triangular superior. El método de Gauss-Jordan continúa el proceso de transformación hasta obtener una matriz diagonal"
] ]
}, },
{
"cell_type": "code",
"execution_count": 1535,
"metadata": {},
"outputs": [],
"source": [
"class Matriz():\n",
" def __init__ (self,matriz):\n",
" self.matriz=np.array(matriz)\n",
" self.no=0\n",
" \n",
" def filas(self):\n",
" return(len(self.matriz))\n",
" \n",
" def columnas(self):\n",
" return(len(self.matriz[0]))\n",
" \n",
" def determinante(self):\n",
" if self.filas()==self.columnas():\n",
" return(np.linalg.det(self.matriz))\n",
" else:\n",
" print(\"Matriz no cuadrada, no existe determinante\")\n",
" self.no=1\n",
" return(self.no)\n",
" \n",
" def gauss(self):\n",
" self.determinante()\n",
" if (self.no==0 and self.determinante()!=0):\n",
" print(\"Determinante distinto de cero:\\nMatriz invertible!\")\n",
" \n",
" #Operaciones\n",
" mAuxiliar=np.identity(self.filas())\n",
" print(mAuxiliar)\n",
" piv = []\n",
" linea=[]\n",
" lineaux=[]\n",
" pivaux=[]\n",
" \n",
" for fila in range(self.filas()):\n",
" for columna in range(self.columnas()):\n",
" if fila==columna:\n",
" print(\"Entra fila=columna\"+ str(fila))\n",
" aux=None\n",
" aux1=None\n",
" aux2=None\n",
" auxR=None\n",
" \n",
" #print(self.matriz[fila][columna])\n",
" aux=1/self.matriz[fila][columna]\n",
" #print(aux)\n",
" #print(\"aqui\")\n",
" #print(self.matriz[fila,:])\n",
" #print(self.matriz[fila,:]*aux)\n",
" self.matriz[fila,:]=self.matriz[fila,:]*aux\n",
" #print(\"aca\")\n",
" #print(self.matriz[fila,:])\n",
" mAuxiliar[fila,:]=mAuxiliar[fila,:]*aux\n",
" aux1=self.matriz[fila,:]\n",
" aux2=mAuxiliar[fila,:]\n",
" linea.append(aux1)\n",
" piv.append(self.matriz[fila][columna])\n",
" lineaux.append(aux2)\n",
" pivaux.append(mAuxiliar[fila][columna])\n",
" #print(\"Resultados\")\n",
" #print(piv)\n",
" #print(linea)\n",
" #print(\"Sobre la identidad\")\n",
" #print(pivaux)\n",
" #print(lineaux)\n",
" #print(\"Resultados matrices\")\n",
" print(self.matriz)\n",
" print(mAuxiliar)\n",
"\n",
" elif fila>columna:\n",
" print(\"Entra fila>columna\"+ str(fila))\n",
" auxR=self.matriz[fila][columna]\n",
" \n",
" #print(\"preuba\")\n",
" #print(linea[columna]*-auxR)\n",
" self.matriz[fila,:]=self.matriz[fila,:]+(linea[columna]*-auxR)\n",
" mAuxiliar[fila,:]=mAuxiliar[fila,:]+(lineaux[columna]*-auxR)\n",
" \n",
" print(\"Resultados matrices\")\n",
" print(self.matriz)\n",
" print(mAuxiliar)\n",
" \n",
" \n",
" else:\n",
" pass\n",
" print(\"intermedio\")\n",
" piv = []\n",
" linea=[]\n",
" lineaux=[]\n",
" pivaux=[] \n",
" \n",
" a=max(range(self.columnas()))\n",
" for columna in range(a,-1,-1):\n",
" for fila in range(a,-1,-1):\n",
" if fila==columna:\n",
" linea.append(self.matriz[fila,:])\n",
" lineaux.append(mAuxiliar[fila,:]) \n",
" \n",
" elif fila>columna:\n",
" pass\n",
" \n",
" elif fila<columna:\n",
" piv.append(self.matriz[fila][columna])\n",
" self.matriz[fila,:]=self.matriz[fila,:]+(linea[-1]*-piv[-1])\n",
" mAuxiliar[fila,:]=mAuxiliar[fila,:]+(lineaux[-1]*-piv[-1])\n",
" print(\"Resultados matrices\")\n",
" print(self.matriz)\n",
" print(mAuxiliar)\n",
" print(\"La inversa es: \\n\")\n",
" return(mAuxiliar)\n",
" \n",
" \n",
" elif self.determinante()==0:\n",
" print(\"Determinante igual a cero:\\nMatriz no invertible\")\n",
" return(0)\n",
" \n",
" elif self.no==1:\n",
" print(\"Matriz no cuadrada:\\nMatriz no invertible\")\n",
" print(\"Inicia proceso de pseudoinversa\")\n",
"\n",
" original=self.matriz\n",
" x=mmult1(self.matriz,original.T)\n",
" x=Matriz(x)\n",
" #print(x)\n",
" #print(self.matriz)\n",
" inve=x.gauss()\n",
" #print(inve)\n",
" soluD=mmult1(original.T,inve)\n",
" #print(soluD)\n",
" \n",
" \n",
" #Por la izquierda\n",
" original=self.matriz\n",
" y=mmult1(original.T,self.matriz)\n",
" y=Matriz(y)\n",
" print(y)\n",
" #print(self.matriz)\n",
" inve=y.gauss()\n",
" #print(inve)\n",
" soluI=mmult1(inve,original.T)\n",
" \n",
" return(soluD, soluI)\n",
" \n",
" \n",
" def __str__ (self):\n",
" return(\"Soy la matriz:\\n\"+ str(self.matriz))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"''' \n",
" else:\n",
" #original=self.matriz\n",
" #x=mmult1(original.T,self.matriz)\n",
" #x=Matriz(x)\n",
" #print(x)\n",
" #print(self.matriz)\n",
" #inve=x.gauss\n",
" #print(inve)\n",
" #mmult1(inve,original.T)\n",
" pass'''"
]
},
{
"cell_type": "code",
"execution_count": 1538,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Soy la matriz:\n",
"[[1400. 970.]\n",
" [ 970. 878.]]\n",
"Soy la matriz:\n",
"[[ 1 2 3]\n",
" [ 4 5 6]\n",
" [ 7 8 10]]\n",
"Soy la matriz:\n",
"[[10. 20. 30.]\n",
" [18. 5. 23.]]\n",
"Soy la matriz:\n",
"[[ 1. 1. 0. 2. -1.]\n",
" [ 0. 0. 2. -1. 2.]\n",
" [ 0. 2. -3. 4. 5.]\n",
" [ 1. 0. -1. 1. 1.]\n",
" [ 0. 0. 0. 0. 4.]]\n"
]
}
],
"source": [
"mmatriz=Matriz(A)\n",
"mmatriz1=Matriz(x)\n",
"mmatriz2=Matriz(y)\n",
"mmatriz3=Matriz(z)\n",
"mmatriz4=Matriz(w)\n",
"print(mmatriz1)\n",
"print(mmatriz2)\n",
"print(mmatriz3)\n",
"print(mmatriz4)"
]
},
{
"cell_type": "code",
"execution_count": 1483,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Soy la matriz:\n",
"[[1400. 970.]\n",
" [ 970. 878.]]\n",
"288300.0\n",
"2\n",
"2\n",
"Determinante distinto de cero:\n",
"Matriz invertible!\n",
"[[1. 0.]\n",
" [0. 1.]]\n",
"Entra fila=columna0\n",
"[[1.00000000e+00 6.92857143e-01]\n",
" [9.70000000e+02 8.78000000e+02]]\n",
"[[7.14285714e-04 0.00000000e+00]\n",
" [0.00000000e+00 1.00000000e+00]]\n",
"Entra fila>columna1\n",
"Resultados matrices\n",
"[[ 1. 0.69285714]\n",
" [ 0. 205.92857143]]\n",
"[[ 7.14285714e-04 0.00000000e+00]\n",
" [-6.92857143e-01 1.00000000e+00]]\n",
"Entra fila=columna1\n",
"[[1. 0.69285714]\n",
" [0. 1. ]]\n",
"[[ 0.00071429 0. ]\n",
" [-0.00336455 0.00485605]]\n",
"intermedio\n",
"Resultados matrices\n",
"[[1.00000000e+00 1.11022302e-16]\n",
" [0.00000000e+00 1.00000000e+00]]\n",
"[[ 0.00304544 -0.00336455]\n",
" [-0.00336455 0.00485605]]\n",
"La inversa es: \n",
"\n"
]
},
{
"data": {
"text/plain": [
"array([[ 0.00304544, -0.00336455],\n",
" [-0.00336455, 0.00485605]])"
]
},
"execution_count": 1483,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print(mmatriz1)\n",
"print(mmatriz1.determinante())\n",
"print(mmatriz1.filas())\n",
"print(mmatriz1.columnas())\n",
"mmatriz1.gauss()"
]
},
{
"cell_type": "code",
"execution_count": 1484,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Soy la matriz:\n",
"[[ 1 2 3]\n",
" [ 4 5 6]\n",
" [ 7 8 10]]\n",
"-2.9999999999999996\n",
"3\n",
"3\n",
"Determinante distinto de cero:\n",
"Matriz invertible!\n",
"[[1. 0. 0.]\n",
" [0. 1. 0.]\n",
" [0. 0. 1.]]\n",
"Entra fila=columna0\n",
"[[ 1 2 3]\n",
" [ 4 5 6]\n",
" [ 7 8 10]]\n",
"[[1. 0. 0.]\n",
" [0. 1. 0.]\n",
" [0. 0. 1.]]\n",
"Entra fila>columna1\n",
"Resultados matrices\n",
"[[ 1 2 3]\n",
" [ 0 -3 -6]\n",
" [ 7 8 10]]\n",
"[[ 1. 0. 0.]\n",
" [-4. 1. 0.]\n",
" [ 0. 0. 1.]]\n",
"Entra fila=columna1\n",
"[[ 1 2 3]\n",
" [ 0 1 2]\n",
" [ 7 8 10]]\n",
"[[ 1. 0. 0. ]\n",
" [ 1.33333333 -0.33333333 -0. ]\n",
" [ 0. 0. 1. ]]\n",
"Entra fila>columna2\n",
"Resultados matrices\n",
"[[ 1 2 3]\n",
" [ 0 1 2]\n",
" [ 0 -6 -11]]\n",
"[[ 1. 0. 0. ]\n",
" [ 1.33333333 -0.33333333 -0. ]\n",
" [-7. 0. 1. ]]\n",
"Entra fila>columna2\n",
"Resultados matrices\n",
"[[1 2 3]\n",
" [0 1 2]\n",
" [0 0 1]]\n",
"[[ 1. 0. 0. ]\n",
" [ 1.33333333 -0.33333333 -0. ]\n",
" [ 1. -2. 1. ]]\n",
"Entra fila=columna2\n",
"[[1 2 3]\n",
" [0 1 2]\n",
" [0 0 1]]\n",
"[[ 1. 0. 0. ]\n",
" [ 1.33333333 -0.33333333 -0. ]\n",
" [ 1. -2. 1. ]]\n",
"intermedio\n",
"Resultados matrices\n",
"[[1 2 3]\n",
" [0 1 0]\n",
" [0 0 1]]\n",
"[[ 1. 0. 0. ]\n",
" [-0.66666667 3.66666667 -2. ]\n",
" [ 1. -2. 1. ]]\n",
"Resultados matrices\n",
"[[1 2 0]\n",
" [0 1 0]\n",
" [0 0 1]]\n",
"[[-2. 6. -3. ]\n",
" [-0.66666667 3.66666667 -2. ]\n",
" [ 1. -2. 1. ]]\n",
"Resultados matrices\n",
"[[1 0 0]\n",
" [0 1 0]\n",
" [0 0 1]]\n",
"[[-0.66666667 -1.33333333 1. ]\n",
" [-0.66666667 3.66666667 -2. ]\n",
" [ 1. -2. 1. ]]\n",
"La inversa es: \n",
"\n"
]
},
{
"data": {
"text/plain": [
"array([[-0.66666667, -1.33333333, 1. ],\n",
" [-0.66666667, 3.66666667, -2. ],\n",
" [ 1. , -2. , 1. ]])"
]
},
"execution_count": 1484,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print(mmatriz2)\n",
"print(mmatriz2.determinante())\n",
"print(mmatriz2.filas())\n",
"print(mmatriz2.columnas())\n",
"mmatriz2.gauss()"
]
},
{
"cell_type": "code",
"execution_count": 1539,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Soy la matriz:\n",
"[[10. 20. 30.]\n",
" [18. 5. 23.]]\n",
"Matriz no cuadrada, no existe determinante\n",
"Matriz no cuadrada, no existe determinante\n",
"Matriz no cuadrada:\n",
"Matriz no invertible\n",
"Inicia proceso de pseudoinversa\n",
"[[0, 0], [0, 0]]\n",
"Determinante distinto de cero:\n",
"Matriz invertible!\n",
"[[1. 0.]\n",
" [0. 1.]]\n",
"Entra fila=columna0\n",
"[[1.00000000e+00 6.92857143e-01]\n",
" [9.70000000e+02 8.78000000e+02]]\n",
"[[7.14285714e-04 0.00000000e+00]\n",
" [0.00000000e+00 1.00000000e+00]]\n",
"Entra fila>columna1\n",
"Resultados matrices\n",
"[[ 1. 0.69285714]\n",
" [ 0. 205.92857143]]\n",
"[[ 7.14285714e-04 0.00000000e+00]\n",
" [-6.92857143e-01 1.00000000e+00]]\n",
"Entra fila=columna1\n",
"[[1. 0.69285714]\n",
" [0. 1. ]]\n",
"[[ 0.00071429 0. ]\n",
" [-0.00336455 0.00485605]]\n",
"intermedio\n",
"Resultados matrices\n",
"[[1.00000000e+00 1.11022302e-16]\n",
" [0.00000000e+00 1.00000000e+00]]\n",
"[[ 0.00304544 -0.00336455]\n",
" [-0.00336455 0.00485605]]\n",
"La inversa es: \n",
"\n",
"[[0, 0], [0, 0], [0, 0]]\n",
"[[0, 0, 0], [0, 0, 0], [0, 0, 0]]\n",
"Soy la matriz:\n",
"[[ 424. 290. 714.]\n",
" [ 290. 425. 715.]\n",
" [ 714. 715. 1429.]]\n",
"Determinante igual a cero:\n",
"Matriz no invertible\n"
]
},
{
"ename": "TypeError",
"evalue": "object of type 'int' has no len()",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-1539-9c911503a563>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmmatriz3\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mmmatriz3\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgauss\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;32m<ipython-input-1535-85fa2830b7e7>\u001b[0m in \u001b[0;36mgauss\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 136\u001b[0m \u001b[0minve\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0my\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgauss\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 137\u001b[0m \u001b[0;31m#print(inve)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 138\u001b[0;31m \u001b[0msoluI\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmmult1\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minve\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0moriginal\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mT\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 139\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 140\u001b[0m \u001b[0;32mreturn\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msoluD\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msoluI\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m<ipython-input-1233-130e02de5586>\u001b[0m in \u001b[0;36mmmult1\u001b[0;34m(m1, m2)\u001b[0m\n\u001b[1;32m 16\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 17\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mmmult1\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mm1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mm2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 18\u001b[0;31m \u001b[0mfila_A\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mm1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 19\u001b[0m \u001b[0mcols_A\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mm1\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 20\u001b[0m \u001b[0mfila_B\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mm2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mTypeError\u001b[0m: object of type 'int' has no len()"
]
}
],
"source": [
"print(mmatriz3)\n",
"mmatriz3.gauss()"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
...@@ -1199,6 +1893,15 @@ ...@@ -1199,6 +1893,15 @@
"Nota: Utilizar arreglos de Numpy\n" "Nota: Utilizar arreglos de Numpy\n"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"***Esta en la clase de arriba"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"metadata": {}, "metadata": {},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment