Commit be8ff03f authored by geobumac's avatar geobumac

inversa

parent 4d26f915
...@@ -900,10 +900,98 @@ ...@@ -900,10 +900,98 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 43,
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [
"source": [] {
"name": "stdout",
"output_type": "stream",
"text": [
"[[1. 0. 0.]\n",
" [0. 1. 0.]\n",
" [0. 0. 1.]]\n",
"-----\n",
"[[ 5 6 7]\n",
" [ 0 1 2]\n",
" [10 11 12]]\n",
"-------------\n",
"+++++++\n",
"[0 1 2]\n",
"[[ 5 6 7]\n",
" [ 0 1 2]\n",
" [10 11 12]]\n",
"+++++++\n",
"[0 1 2]\n",
"[[ 5 6 7]\n",
" [ 0 1 2]\n",
" [10 11 12]]\n",
"-------------\n",
"+++++++\n",
"[ 2 11 12]\n",
"[[ 5 6 7]\n",
" [ 0 1 2]\n",
" [ 2 -1 12]]\n",
"+++++++\n",
"[ 2 -1 12]\n",
"[[ 5 6 7]\n",
" [ 0 1 2]\n",
" [ 2 -1 -2]]\n",
"-------------\n",
"+++++++\n",
"[ 2 -1 -2]\n",
"[[ 5 6 7]\n",
" [ 0 1 2]\n",
" [ 2 -1 0]]\n"
]
}
],
"source": [
"import numpy as np\n",
"class Gaus:\n",
" def __init__(self, matriz):\n",
" self.matriz = np.array(matriz)\n",
" \n",
" def swap(self, row1, row2):\n",
" matriz = self.matriz\n",
" auxrow = np.copy(matriz[row1]);\n",
" self.matriz[row1] = self.matriz[row2]\n",
" self.matriz[row2] = auxrow\n",
" print(\"-----\")\n",
" print(self.matriz)\n",
" \n",
" def solver(self):\n",
" matriz = self.matriz\n",
" auxmatriz = np.copy(matriz);\n",
" shapem = matriz.shape\n",
" if shapem[0] != shapem[1]:\n",
" print(\"no singular\")\n",
" else:\n",
" self.identity = np.eye(shapem[0])\n",
" print(self.identity)\n",
" if matriz[0][0] == 0:\n",
" self.swap(0,1)\n",
" \n",
" for fila_pivote in range(shapem[0] - 1):\n",
" for fila_pivote_mas1 in range(fila_pivote + 1, shapem[0]):\n",
" print(\"-------------\")\n",
" #print(matriz[fila_pivote_mas1][fila_pivote])\n",
" #print(matriz[fila_pivote][fila_pivote])\n",
" multiplicador = matriz[fila_pivote_mas1][fila_pivote]/matriz[fila_pivote][fila_pivote]\n",
" matriz[fila_pivote_mas1][fila_pivote] = multiplicador\n",
" for col in range(fila_pivote + 1, shapem[0]):\n",
" print(\"+++++++\")\n",
" print(matriz[fila_pivote_mas1])\n",
" matriz[fila_pivote_mas1][col] = matriz[fila_pivote_mas1][col] - multiplicador*matriz[fila_pivote][col]\n",
" \n",
" print(matriz)\n",
" \n",
" \n",
"a = np.floor(10*np.random.random((3,4)))\n",
"gaus = Gaus([[0,1,2],\n",
" [ 5,6,7],\n",
" [10,11,12]])\n",
"gaus.solver()"
]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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