{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: nacal in /home/marcos/.local/lib/python3.9/site-packages (0.1.13)\n", "Requirement already satisfied: sympy>=1.1.0 in /usr/lib/python3/dist-packages (from nacal) (1.7.1)\n", "Note: you may need to restart the kernel to use updated packages.\n" ] } ], "source": [ "pip install nacal" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "from nacal import *\n", "from IPython.display import display, Math" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "$\n", "\\renewcommand{\\R}[1][{}]{{\\mathbb{R}}^{#1}}\n", "\\renewcommand{\\Z}[1][{}]{{\\mathbb{Z}}^{#1}}\n", "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", "\\renewcommand{\\getitemR}[1]{\\getItem{#1}}\n", "\\renewcommand{\\getItem}{\\pmb{\\mid}}\n", "\\renewcommand{\\elemR}[2]{{#1}^{\\phantom{\\T}}_{\\getitemR{#2}}} \n", "\\renewcommand{\\elemRP}[2]{{\\big(#1\\big)}^{\\phantom{\\T}}_{\\getitemR{#2}}} \n", "\\renewcommand{\\elemRPE}[2]{\\big({#1}^{\\phantom{\\T}}_{\\getitemR{#2}}\\big)}\n", "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", "\\renewcommand{\\Vect}[2][{}]{{\\boldsymbol{#2}}_{#1}}\n", "\\renewcommand{\\eleVR}[2] {\\elemR {\\Vect{#1}}{#2}}\t % con subindices\n", "\\renewcommand{\\eleVRP}[2] {\\elemRP {\\Vect{#1}}{#2}} % con subindices y paréntesis interior\n", "\\renewcommand{\\eleVRPE}[2]{\\elemRPE{\\Vect{#1}}{#2}} % con subindices y paréntesis exterior\n", "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", "\\renewcommand{\\VectC}[2][{}] {\\elemR {\\Mat{#2}}{#1}} % con subindices\n", "\\renewcommand{\\VectCP}[2][{}] {\\elemRP {\\Mat{#2}}{#1}} % con subindices y paréntesis\n", "\\renewcommand{\\VectCPE}[2][{}]{\\elemRPE{\\Mat{#2}}{#1}} % con subindices y paréntesis exterior\n", "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n", "\\renewcommand{\\mat}[1]{\\mathbf{#1}}\n", "\\renewcommand{\\Mat} [2][{}]{{\\mat{#2}}_{#1}} \n", "\\renewcommand{\\T}{\\intercal}\n", "\\renewcommand{\\MatT}[2][{}]{{\\mat{#2}}^{\\T}_{#1}}\n", "\\renewcommand{\\VectC}[2][{}] {\\elemR {\\Mat{#2}}{#1}} % con subindices\n", "\\renewcommand{\\VectCP}[2][{}] {\\elemRP {\\Mat{#2}}{#1}} % con subindices y paréntesis\n", "\\renewcommand{\\VectCPE}[2][{}] {\\elemRPE {\\Mat{#2}}{#1}} % con subindices y paréntesis exterior\n", "\\renewcommand{\\VectCC}[2][{}] {\\elemRR {\\Mat{#2}}{#1}} % con ()\n", "\\renewcommand{\\VectCCC}[2][{}] {\\elemRRR{\\Mat{#2}}{#1}} % con texto \"col\"\n", "%SELECCIÓNA de FILAS y COlUMNAS DE UNA MATRIZ TRANSPUESTA PARA GENERAR UN VECTOR DE Rn\n", "\\renewcommand{\\VectTC}[2][{}] {\\elemR{\\MatT{#2}\\!}{#1}} % con subindices\n", "\\renewcommand{\\VectTCC}[2][{}] {\\elemRR{ \\MatT{#2}}{#1}} % con ()\n", "\\renewcommand{\\VectTCCC}[2][{}] {\\elemRRR{\\MatT{#2}}{#1}} % con texto \"col\"\n", "$" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "${\\huge\\text{Jupyter notebook de la Lección 5}}$" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "**Índice de contenidos de este notebook** (Requiere ejecutar todo el Notebook para que aparezca el índice)\n", "
" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "# Matrices invertibles\n", "\n", "Considere las siguientes matrices cuadradas\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccc}\\frac{3}{4}&\\frac{1}{2}&\\frac{1}{4}\\\\\\frac{1}{2}&1&\\frac{1}{2}\\\\\\frac{1}{4}&\\frac{1}{2}&\\frac{3}{4}\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([3/4, 1/2, 1/4]), Vector([1/2, 1, 1/2]), Vector([1/4, 1/2, 3/4])])" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A = Matrix([Vector([fracc(3, 4), fracc(1, 2), fracc(1, 4)]), \\\n", " Vector([fracc(1, 2), fracc(1, 1), fracc(1, 2)]), \\\n", " Vector([fracc(1, 4), fracc(1, 2), fracc(3, 4)])])\n", "A" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccc}2&-1&0\\\\-1&2&-1\\\\0&-1&2\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([2, -1, 0]), Vector([-1, 2, -1]), Vector([0, -1, 2])])" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "B = Matrix([[2,-1,0],[-1,2,-1],[0,-1,2]])\n", "B" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "Si las multiplicamos, obtenemos la matriz identidad. " ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccc}1&0&0\\\\0&1&0\\\\0&0&1\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([1, 0, 0]), Vector([0, 1, 0]), Vector([0, 0, 1])])" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A*B" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "Cuando multiplicamos dos matrices _cuadradas_ `A` y `B` y obtenemos la matriz identidad, decimos que `A` es la inversa de `B` y que `B` es la inversa de `A`. En tal caso, `B*A` también en la matriz identidad." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccc}1&0&0\\\\0&1&0\\\\0&0&1\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([1, 0, 0]), Vector([0, 1, 0]), Vector([0, 0, 1])])" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "B*A" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "## Inversas de matrices elementales e inversas de transformaciones elementales\n", "\n", "\n", "Cuando una matriz tiene inversa, decimos que es _invertible_. Por ejemplo" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccc}1&0&0\\\\0&1&0\\\\0&0&1\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([1, 0, 0]), Vector([0, 1, 0]), Vector([0, 0, 1])])" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "( I(3) & T((-1,2,3)) ) * ( I(3) & T((1,2,3)) )" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "que es lo mismo que `I(3) & T((-1,2,3) & T((1,2,3))`, o que " ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccc}1&0&0\\\\0&1&0\\\\0&0&1\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([1, 0, 0]), Vector([0, 1, 0]), Vector([0, 0, 1])])" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "I(3) & T( [(-1,2,3), (1,2,3) ] ) " ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "Es decir, la secuencia de transformaciones `T( [(-1,2,3), (1,2,3) ] )` cambia la matriz sobre la que actua." ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccc}2&-1&0\\\\-1&2&-1\\\\0&-1&2\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([2, -1, 0]), Vector([-1, 2, -1]), Vector([0, -1, 2])])" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "B & T( [(-1,2,3), (1,2,3) ] )" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "En este caso se dice que `T((-1,2,3))` es la _inversa_ de la transformación `T((1,2,3))`, pues una deshace los cambios realizados por la otra." ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "Con `**` calculamos las potencias de una transformación elemental. Por ejemplo podemos calcular el cuadrado de una transformación " ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "

$\\underset{\\begin{subarray}{c} \\left[\\left(5\\right)\\mathbf{3}\\right]\\\\\\left[\\left(5\\right)\\mathbf{3}\\right]\\end{subarray}}{\\pmb{\\tau}}$

" ], "text/plain": [ "T([(5, 3), (5, 3)])" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "T( (5,3) )**2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Pero también su _inversa_" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\underset{\\begin{subarray}{c} \\left[\\left(\\frac{1}{5}\\right)\\mathbf{3}\\right]\\end{subarray}}{\\pmb{\\tau}}$

" ], "text/plain": [ "T([(1/5, 3)])" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "T( (5,3) )**(-1)" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "Pero tambien potencias de una secuencia de transformaciones" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\underset{\\begin{subarray}{c} \\left[\\mathbf{2}\\rightleftharpoons\\mathbf{3}\\right]\\\\\\left[\\left(-2\\right)\\mathbf{4}\\right]\\\\\\left[\\left(1\\right)\\mathbf{2}+\\mathbf{3} \\right]\\\\\\left[\\mathbf{2}\\rightleftharpoons\\mathbf{3}\\right]\\\\\\left[\\left(-2\\right)\\mathbf{4}\\right]\\\\\\left[\\left(1\\right)\\mathbf{2}+\\mathbf{3} \\right]\\end{subarray}}{\\pmb{\\tau}}$

" ], "text/plain": [ "T([{2, 3}, (-2, 4), (1, 2, 3), {2, 3}, (-2, 4), (1, 2, 3)])" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "k=T( [T({2,3}), T([(-2,4), (1,2,3)]) ] )\n", "k**2" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\underset{\\begin{subarray}{c} \\left[\\left(-1\\right)\\mathbf{2}+\\mathbf{3} \\right]\\\\\\left[\\left(- \\frac{1}{2}\\right)\\mathbf{4}\\right]\\\\\\left[\\mathbf{2}\\rightleftharpoons\\mathbf{3}\\right]\\end{subarray}}{\\pmb{\\tau}}$

" ], "text/plain": [ "T([(-1, 2, 3), (-1/2, 4), {2, 3}])" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "kinv = k**(-1)\n", "kinv" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "Así pues, al aplicar la secuencia y su inversa, la matriz se mantiene sin cambios" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{cccc}1&0&0&0\\\\0&1&0&0\\\\0&0&1&0\\\\0&0&0&1\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([1, 0, 0, 0]), Vector([0, 1, 0, 0]), Vector([0, 0, 1, 0]), Vector([0, 0, 0, 1])])" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "I(4) & k & kinv" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "Fíjese que para invertir una secuencia de transformaciones, las transformaciones inversas se aplican en el orden inverso la ultima aplicada es la primera en ser invertida, la penúltima aplicada es la segunda en ser invertida, etc. " ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\underset{\\begin{subarray}{c} \\left[\\mathbf{2}\\rightleftharpoons\\mathbf{3}\\right]\\\\\\left[\\left(-2\\right)\\mathbf{4}\\right]\\\\\\left[\\left(1\\right)\\mathbf{2}+\\mathbf{3} \\right]\\\\\\left[\\left(-1\\right)\\mathbf{2}+\\mathbf{3} \\right]\\\\\\left[\\left(- \\frac{1}{2}\\right)\\mathbf{4}\\right]\\\\\\left[\\mathbf{2}\\rightleftharpoons\\mathbf{3}\\right]\\end{subarray}}{\\pmb{\\tau}}$

" ], "text/plain": [ "T([{2, 3}, (-2, 4), (1, 2, 3), (-1, 2, 3), (-1/2, 4), {2, 3}])" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "k & kinv" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\underset{\\begin{subarray}{c} \\left[\\left(-1\\right)\\mathbf{2}+\\mathbf{3} \\right]\\\\\\left[\\left(- \\frac{1}{2}\\right)\\mathbf{4}\\right]\\\\\\left[\\mathbf{2}\\rightleftharpoons\\mathbf{3}\\right]\\\\\\left[\\mathbf{2}\\rightleftharpoons\\mathbf{3}\\right]\\\\\\left[\\left(-2\\right)\\mathbf{4}\\right]\\\\\\left[\\left(1\\right)\\mathbf{2}+\\mathbf{3} \\right]\\end{subarray}}{\\pmb{\\tau}}$

" ], "text/plain": [ "T([(-1, 2, 3), (-1/2, 4), {2, 3}, {2, 3}, (-2, 4), (1, 2, 3)])" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "kinv & k" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "# Comprobando si una matriz cuadrada es invertible.\n", "\n", "Un matriz cuadrada de orden $n$ es invertible si cualquiera de sus\n", "formas escalonadas tiene $n$ pivotes. \n", "\n", "¿Es invertible la siguiente matriz `C`?" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccc}1&1&-2\\\\1&-2&1\\\\-2&1&1\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([1, 1, -2]), Vector([1, -2, 1]), Vector([-2, 1, 1])])" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "C = Matrix([[1,1,-2],[1,-2,1],[-2,1,1]])\n", "C" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccc}1&0&0\\\\1&-3&0\\\\-2&3&0\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([1, 1, -2]), Vector([0, -3, 3]), Vector([0, 0, 0])])" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ElimG(C)" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "¿Y la matriz `M` de más abajo?" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccccc}1&2&3&4&5\\\\0&0&-1&-9&1\\\\1&4&6&0&0\\\\0&1&0&1&0\\\\1&0&1&0&1\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([1, 0, 1, 0, 1]), Vector([2, 0, 4, 1, 0]), Vector([3, -1, 6, 0, 1]), Vector([4, -9, 0, 1, 0]), Vector([5, 1, 0, 0, 1])])" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M = Matrix([[1,2,3,4,5],[0,0,-1,-9,1],[1,4,6,0,0],[0,1,0,1,0],[1,0,1,0,1]])\n", "M" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccccc}1&0&0&0&0\\\\0&-2&0&0&0\\\\1&0&2&0&0\\\\0&-3&1&33&0\\\\1&2&-2&-34&-230\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([1, 0, 1, 0, 1]), Vector([0, -2, 0, -3, 2]), Vector([0, 0, 2, 1, -2]), Vector([0, 0, 0, 33, -34]), Vector([0, 0, 0, 0, -230])])" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ElimG(M)" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "# Invirtiendo una matriz\n", "\n", "¿Se le ocurre como continuar para llegar a obtener la matriz identidad de orden 5? Dado lo visto en el Notebook de la Lección 4, se dará cuenta que basta con aplicar la elimnación Gauss-Jordan." ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccccc}1&0&0&0&0\\\\0&1&0&0&0\\\\0&0&1&0&0\\\\0&0&0&1&0\\\\0&0&0&0&1\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([1, 0, 0, 0, 0]), Vector([0, 1, 0, 0, 0]), Vector([0, 0, 1, 0, 0]), Vector([0, 0, 0, 1, 0]), Vector([0, 0, 0, 0, 1])])" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ElimGJ(M)" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "Ahora piense que en el atributo `pasos` del resultado están\n", "almacenadas todas la abreviaturas de los pasos dados para llegar a\n", "transformar la matriz `M` en la matriz identidad. Se le ocurre cómo\n", "obtener con dichos pasos una matriz tal que multiplicada por `M` nos\n", "dé la matriz identidad? Si no se le ocurre, repase el Notebook de la\n", "Leeción 4." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "Y si hubiera intentado la misma estrategia con la matriz `C` ¿hubiera\n", "logrado obtener la matriz identidad de orden 3? Si no lo ve claro,\n", "repita la estrategia con `C` en el siguiente recuadro." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "Al principio de este notebook hemos visto que la matriz `B` es\n", "invertible. De hecho, encadenando transformaciones que finalmente nos den una matriz diagonal con los pivotes iguales a 1 obtenemos la matriz identidad. Por ejemplo, podemos usar la elimnación Gauss-Jordan que normaliza los pivotes. Guardemos en `p` los pasos dados" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[ \\begin{array}{ccc}2&-1&0\\\\-1&2&-1\\\\0&-1&2\\\\ \\end{array} \\right]\\xrightarrow{\\underset{\\begin{subarray}{c} \\left[\\left(2\\right)\\mathbf{2}\\right]\\\\\\left[\\left(1\\right)\\mathbf{1}+\\mathbf{2} \\right]\\end{subarray}}{\\pmb{\\tau}}}\\left[ \\begin{array}{ccc}2&0&0\\\\-1&3&-1\\\\0&-2&2\\\\ \\end{array} \\right]\\xrightarrow{\\underset{\\begin{subarray}{c} \\left[\\left(3\\right)\\mathbf{3}\\right]\\\\\\left[\\left(1\\right)\\mathbf{2}+\\mathbf{3} \\right]\\end{subarray}}{\\pmb{\\tau}}}\\left[ \\begin{array}{ccc}2&0&0\\\\-1&3&0\\\\0&-2&4\\\\ \\end{array} \\right]\\xrightarrow{\\underset{\\begin{subarray}{c} \\left[\\left(3\\right)\\mathbf{1}\\right]\\\\\\left[\\left(1\\right)\\mathbf{2}+\\mathbf{1} \\right]\\end{subarray}}{\\pmb{\\tau}}}\\left[ \\begin{array}{ccc}6&0&0\\\\0&3&0\\\\-2&-2&4\\\\ \\end{array} \\right]\\xrightarrow{\\underset{\\begin{subarray}{c} \\left[\\left(2\\right)\\mathbf{1}\\right]\\\\\\left[\\left(1\\right)\\mathbf{3}+\\mathbf{1} \\right]\\\\\\left[\\left(2\\right)\\mathbf{2}\\right]\\\\\\left[\\left(1\\right)\\mathbf{3}+\\mathbf{2} \\right]\\end{subarray}}{\\pmb{\\tau}}}\\left[ \\begin{array}{ccc}12&0&0\\\\0&6&0\\\\0&0&4\\\\ \\end{array} \\right]\\xrightarrow{\\underset{\\begin{subarray}{c} \\left[\\left(\\frac{1}{12}\\right)\\mathbf{1}\\right]\\\\\\left[\\left(\\frac{1}{6}\\right)\\mathbf{2}\\right]\\\\\\left[\\left(\\frac{1}{4}\\right)\\mathbf{3}\\right]\\end{subarray}}{\\pmb{\\tau}}}\\left[ \\begin{array}{ccc}1&0&0\\\\0&1&0\\\\0&0&1\\\\ \\end{array} \\right]$" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "p = ElimGJ(B,1).pasos" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "En el procedimiento de más arriba, las transformaciones elementales solo han actuado sobre las columnas, de manera que con dichas tranformaciones aplicadas sobre las _columnas_ de `B` obtenemos la matriz identidad\n", "$$\n", "\\Mat[{\\mathbf{\\tau}_{1}\\dots\\mathbf{\\tau}_{k}}]{B}\n", "=\n", "\\Mat{I}\n", "$$" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "scrolled": true, "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccc}1&0&0\\\\0&1&0\\\\0&0&1\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([1, 0, 0]), Vector([0, 1, 0]), Vector([0, 0, 1])])" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Matrix(B) & T(p[1])" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "Así pues, aplicando dicho pasos sobre las _columnas_ de la matriz identidad obtendremos `A` (que es la invesa de `B`)\n", "$$\n", "\\Mat[{\\mathbf{\\tau}_{1}\\dots\\mathbf{\\tau}_{k}}]{B}\n", "=\n", "\\Mat{B}\\Big(\\Mat[{\\mathbf{\\tau}_{1}\\dots\\mathbf{\\tau}_{k}}]{I}\\Big)\n", "=\n", "\\Mat{I}\n", "$$" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccc}\\frac{3}{4}&\\frac{1}{2}&\\frac{1}{4}\\\\\\frac{1}{2}&1&\\frac{1}{2}\\\\\\frac{1}{4}&\\frac{1}{2}&\\frac{3}{4}\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([3/4, 1/2, 1/4]), Vector([1/2, 1, 1/2]), Vector([1/4, 1/2, 3/4])])" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "I(B.n) & T(p[1])" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "donde la sucesión de transformaciones $({\\mathbf{\\tau}_{1}\\dots\\mathbf{\\tau}_{k}})$ es `T(p[1])`. " ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "Es decir, si aplicamos una sucesión de transformaciones que transforman una matriz cuadrada en la matriz identidad " ] }, { "cell_type": "raw", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "Matrix(B) & T(p[1])" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "La misma sucesión de transformaciones `T(p[1])` aplicada a la matriz identidad del mismo orden nos da la matriz inversa" ] }, { "cell_type": "raw", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "I(B.n) & T(p[1])" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "El procedimiento visto en el aula y en las notas de clase para encontrar la inversa usando lápiz y papel elimina componentes a derecha e izquieda de cada pivote y normaliza los pivotes para que sean iguales a 1. Una implementación de esto es la subclase `Inversa` de nuestra libreria. En su atributo pasos están todas las transformaciones aplicadas sobre las columnas." ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "scrolled": true, "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[ \\begin{array}{ccc}2&-1&0\\\\-1&2&-1\\\\0&-1&2\\\\ \\hline 1&0&0\\\\0&1&0\\\\0&0&1\\\\ \\end{array} \\right]\\xrightarrow{\\underset{\\begin{subarray}{c} \\left[\\left(2\\right)\\mathbf{2}\\right]\\\\\\left[\\left(1\\right)\\mathbf{1}+\\mathbf{2} \\right]\\end{subarray}}{\\pmb{\\tau}}}\\left[ \\begin{array}{ccc}2&0&0\\\\-1&3&-1\\\\0&-2&2\\\\ \\hline 1&1&0\\\\0&2&0\\\\0&0&1\\\\ \\end{array} \\right]\\xrightarrow{\\underset{\\begin{subarray}{c} \\left[\\left(3\\right)\\mathbf{3}\\right]\\\\\\left[\\left(1\\right)\\mathbf{2}+\\mathbf{3} \\right]\\end{subarray}}{\\pmb{\\tau}}}\\left[ \\begin{array}{ccc}2&0&0\\\\-1&3&0\\\\0&-2&4\\\\ \\hline 1&1&1\\\\0&2&2\\\\0&0&3\\\\ \\end{array} \\right]\\xrightarrow{\\underset{\\begin{subarray}{c} \\left[\\left(3\\right)\\mathbf{1}\\right]\\\\\\left[\\left(1\\right)\\mathbf{2}+\\mathbf{1} \\right]\\end{subarray}}{\\pmb{\\tau}}}\\left[ \\begin{array}{ccc}6&0&0\\\\0&3&0\\\\-2&-2&4\\\\ \\hline 4&1&1\\\\2&2&2\\\\0&0&3\\\\ \\end{array} \\right]\\xrightarrow{\\underset{\\begin{subarray}{c} \\left[\\left(2\\right)\\mathbf{1}\\right]\\\\\\left[\\left(1\\right)\\mathbf{3}+\\mathbf{1} \\right]\\\\\\left[\\left(2\\right)\\mathbf{2}\\right]\\\\\\left[\\left(1\\right)\\mathbf{3}+\\mathbf{2} \\right]\\end{subarray}}{\\pmb{\\tau}}}\\left[ \\begin{array}{ccc}12&0&0\\\\0&6&0\\\\0&0&4\\\\ \\hline 9&3&1\\\\6&6&2\\\\3&3&3\\\\ \\end{array} \\right]\\xrightarrow{\\underset{\\begin{subarray}{c} \\left[\\left(\\frac{1}{12}\\right)\\mathbf{1}\\right]\\\\\\left[\\left(\\frac{1}{6}\\right)\\mathbf{2}\\right]\\\\\\left[\\left(\\frac{1}{4}\\right)\\mathbf{3}\\right]\\end{subarray}}{\\pmb{\\tau}}}\\left[ \\begin{array}{ccc}1&0&0\\\\0&1&0\\\\0&0&1\\\\ \\hline \\frac{3}{4}&\\frac{1}{2}&\\frac{1}{4}\\\\\\frac{1}{2}&1&\\frac{1}{2}\\\\\\frac{1}{4}&\\frac{1}{2}&\\frac{3}{4}\\\\ \\end{array} \\right]$" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "B = Matrix([[2,-1,0],[-1,2,-1],[0,-1,2]])\n", "p=InvMat(B,1).pasos" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "# Una matriz es invertible si es producto de matrices elementales.\n", "\n", "\n", "Si $\\Mat{B}$ es invertible, entonces $\\Mat{B}$ es la inversa de su inversa, es decir, la inversa de $\\Mat[{\\mathbf{\\tau}_{1}\\dots\\mathbf{\\tau}_{k}}]{I}$, y por tanto $\\Mat{B}$ es producto de matrices elementales. Veamos que efectivamente $\\Mat[({\\mathbf{\\tau}_{1}\\dots\\mathbf{\\tau}_{k}})^{-1}]{I}\\;$ (que es un producto de matrices elementales) es $\\Mat{B}$:" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccc}2&-1&0\\\\-1&2&-1\\\\0&-1&2\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([2, -1, 0]), Vector([-1, 2, -1]), Vector([0, -1, 2])])" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p=InvMat(B).pasos\n", "I(3) & T(p[1])**-1" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "# El procedimiento para invertir una matriz no es único\n", "\n", "## Operando con las filas\n", "\n", "Por supuesto, también se puede invertir una matiz realizando operaciones con sus filas. Por ejemplo, `ElimGJF` obtiene la forma escalonada reducida por filas" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[ \\begin{array}{ccc}2&-1&0\\\\-1&2&-1\\\\0&-1&2\\\\ \\end{array} \\right]\\xrightarrow[\\underset{\\begin{subarray}{c} \\left[\\left(1\\right)\\mathbf{1}+\\mathbf{2} \\right]\\\\\\left[\\left(2\\right)\\mathbf{2}\\right]\\end{subarray}}{\\pmb{\\tau}}]{}\\left[ \\begin{array}{ccc}2&-1&0\\\\0&3&-2\\\\0&-1&2\\\\ \\end{array} \\right]\\xrightarrow[\\underset{\\begin{subarray}{c} \\left[\\left(1\\right)\\mathbf{2}+\\mathbf{3} \\right]\\\\\\left[\\left(3\\right)\\mathbf{3}\\right]\\end{subarray}}{\\pmb{\\tau}}]{}\\left[ \\begin{array}{ccc}2&-1&0\\\\0&3&-2\\\\0&0&4\\\\ \\end{array} \\right]\\xrightarrow[\\underset{\\begin{subarray}{c} \\left[\\left(1\\right)\\mathbf{2}+\\mathbf{1} \\right]\\\\\\left[\\left(3\\right)\\mathbf{1}\\right]\\end{subarray}}{\\pmb{\\tau}}]{}\\left[ \\begin{array}{ccc}6&0&-2\\\\0&3&-2\\\\0&0&4\\\\ \\end{array} \\right]\\xrightarrow[\\underset{\\begin{subarray}{c} \\left[\\left(1\\right)\\mathbf{3}+\\mathbf{2} \\right]\\\\\\left[\\left(2\\right)\\mathbf{2}\\right]\\\\\\left[\\left(1\\right)\\mathbf{3}+\\mathbf{1} \\right]\\\\\\left[\\left(2\\right)\\mathbf{1}\\right]\\end{subarray}}{\\pmb{\\tau}}]{}\\left[ \\begin{array}{ccc}12&0&0\\\\0&6&0\\\\0&0&4\\\\ \\end{array} \\right]\\xrightarrow[\\underset{\\begin{subarray}{c} \\left[\\left(\\frac{1}{4}\\right)\\mathbf{3}\\right]\\\\\\left[\\left(\\frac{1}{6}\\right)\\mathbf{2}\\right]\\\\\\left[\\left(\\frac{1}{12}\\right)\\mathbf{1}\\right]\\end{subarray}}{\\pmb{\\tau}}]{}\\left[ \\begin{array}{ccc}1&0&0\\\\0&1&0\\\\0&0&1\\\\ \\end{array} \\right]$" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "pf=ElimGJF(B,1).pasos" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "por lo que aplicando las trasformaciones almacenadas en `pf` sobre las filas de `B` obtenemos la matriz identidad" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccc}1&0&0\\\\0&1&0\\\\0&0&1\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([1, 0, 0]), Vector([0, 1, 0]), Vector([0, 0, 1])])" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "T(pf[0]) & Matrix(B)" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "lo que quiere decir que aplicando dichas transformaciones a las filas de la matriz identidad obtenemos la inversa" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccc}\\frac{3}{4}&\\frac{1}{2}&\\frac{1}{4}\\\\\\frac{1}{2}&1&\\frac{1}{2}\\\\\\frac{1}{4}&\\frac{1}{2}&\\frac{3}{4}\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([3/4, 1/2, 1/4]), Vector([1/2, 1, 1/2]), Vector([1/4, 1/2, 3/4])])" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "T(pf[0]) & I(B.m)" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "Esto está implementado en `InversaF`, de manera que en lugar de alargar las columnas se alargan las filas" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[ \\begin{array}{ccc|ccc}2&-1&0&1&0&0\\\\-1&2&-1&0&1&0\\\\0&-1&2&0&0&1\\\\ \\end{array} \\right]\\xrightarrow[\\underset{\\begin{subarray}{c} \\left[\\left(1\\right)\\mathbf{1}+\\mathbf{2} \\right]\\\\\\left[\\left(2\\right)\\mathbf{2}\\right]\\end{subarray}}{\\pmb{\\tau}}]{}\\left[ \\begin{array}{ccc|ccc}2&-1&0&1&0&0\\\\0&3&-2&1&2&0\\\\0&-1&2&0&0&1\\\\ \\end{array} \\right]\\xrightarrow[\\underset{\\begin{subarray}{c} \\left[\\left(1\\right)\\mathbf{2}+\\mathbf{3} \\right]\\\\\\left[\\left(3\\right)\\mathbf{3}\\right]\\end{subarray}}{\\pmb{\\tau}}]{}\\left[ \\begin{array}{ccc|ccc}2&-1&0&1&0&0\\\\0&3&-2&1&2&0\\\\0&0&4&1&2&3\\\\ \\end{array} \\right]\\xrightarrow[\\underset{\\begin{subarray}{c} \\left[\\left(1\\right)\\mathbf{2}+\\mathbf{1} \\right]\\\\\\left[\\left(3\\right)\\mathbf{1}\\right]\\end{subarray}}{\\pmb{\\tau}}]{}\\left[ \\begin{array}{ccc|ccc}6&0&-2&4&2&0\\\\0&3&-2&1&2&0\\\\0&0&4&1&2&3\\\\ \\end{array} \\right]\\xrightarrow[\\underset{\\begin{subarray}{c} \\left[\\left(1\\right)\\mathbf{3}+\\mathbf{2} \\right]\\\\\\left[\\left(2\\right)\\mathbf{2}\\right]\\\\\\left[\\left(1\\right)\\mathbf{3}+\\mathbf{1} \\right]\\\\\\left[\\left(2\\right)\\mathbf{1}\\right]\\end{subarray}}{\\pmb{\\tau}}]{}\\left[ \\begin{array}{ccc|ccc}12&0&0&9&6&3\\\\0&6&0&3&6&3\\\\0&0&4&1&2&3\\\\ \\end{array} \\right]\\xrightarrow[\\underset{\\begin{subarray}{c} \\left[\\left(\\frac{1}{4}\\right)\\mathbf{3}\\right]\\\\\\left[\\left(\\frac{1}{6}\\right)\\mathbf{2}\\right]\\\\\\left[\\left(\\frac{1}{12}\\right)\\mathbf{1}\\right]\\end{subarray}}{\\pmb{\\tau}}]{}\\left[ \\begin{array}{ccc|ccc}1&0&0&\\frac{3}{4}&\\frac{1}{2}&\\frac{1}{4}\\\\0&1&0&\\frac{1}{2}&1&\\frac{1}{2}\\\\0&0&1&\\frac{1}{4}&\\frac{1}{2}&\\frac{3}{4}\\\\ \\end{array} \\right]$" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "Binv=InvMatF(B,1)" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "## Operando tanto con las filas como con las columnas\n", "\n", "... ¿y por qué no aplicar operaciones tanto sobre las filas como sobre\n", "las columnas? Como ahora veremos, no es muy práctico; pero desde\n", "luego se puede hacer. Por ejemplo, encadenemos `EGCN` a `EGF`" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[ \\begin{array}{ccc}2&-1&0\\\\-1&2&-1\\\\0&-1&2\\\\ \\end{array} \\right]\\xrightarrow[\\underset{\\begin{subarray}{c} \\left[\\left(1\\right)\\mathbf{1}+\\mathbf{2} \\right]\\\\\\left[\\left(2\\right)\\mathbf{2}\\right]\\end{subarray}}{\\pmb{\\tau}}]{}\\left[ \\begin{array}{ccc}2&-1&0\\\\0&3&-2\\\\0&-1&2\\\\ \\end{array} \\right]\\xrightarrow[\\underset{\\begin{subarray}{c} \\left[\\left(1\\right)\\mathbf{2}+\\mathbf{3} \\right]\\\\\\left[\\left(3\\right)\\mathbf{3}\\right]\\end{subarray}}{\\pmb{\\tau}}]{}\\left[ \\begin{array}{ccc}2&-1&0\\\\0&3&-2\\\\0&0&4\\\\ \\end{array} \\right]\\xrightarrow{\\underset{\\begin{subarray}{c} \\left[\\left(2\\right)\\mathbf{2}\\right]\\\\\\left[\\left(1\\right)\\mathbf{1}+\\mathbf{2} \\right]\\end{subarray}}{\\pmb{\\tau}}}\\left[ \\begin{array}{ccc}2&0&0\\\\0&6&-2\\\\0&0&4\\\\ \\end{array} \\right]\\xrightarrow{\\underset{\\begin{subarray}{c} \\left[\\left(3\\right)\\mathbf{3}\\right]\\\\\\left[\\left(1\\right)\\mathbf{2}+\\mathbf{3} \\right]\\end{subarray}}{\\pmb{\\tau}}}\\left[ \\begin{array}{ccc}2&0&0\\\\0&6&0\\\\0&0&12\\\\ \\end{array} \\right]\\xrightarrow{\\underset{\\begin{subarray}{c} \\left[\\left(\\frac{1}{2}\\right)\\mathbf{1}\\right]\\\\\\left[\\left(\\frac{1}{6}\\right)\\mathbf{2}\\right]\\\\\\left[\\left(\\frac{1}{12}\\right)\\mathbf{3}\\right]\\end{subarray}}{\\pmb{\\tau}}}\\left[ \\begin{array}{ccc}1&0&0\\\\0&1&0\\\\0&0&1\\\\ \\end{array} \\right]$" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "pfc=ElimGJ(ElimGF(B),1).pasos" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "en `pfc` están almacenados los `pasos` aplicados tanto sobre las filas\n", "como sobre las columnas. Así aplicando `T(pfc[0])` por la izquierda\n", "(filas) como `T(pfc[1])` por la derecha (columnas) sobre la matriz\n", "`B`, obtendremos la matriz identidad." ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccc}1&0&0\\\\0&1&0\\\\0&0&1\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([1, 0, 0]), Vector([0, 1, 0]), Vector([0, 0, 1])])" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "T(pfc[0]) & Matrix(B) & T(pfc[1])" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "Si por una parte llamamos $\\Mat{F}$ al producto de matrices elementales \n", "\n", "`T(pfc[0]) & I(3)`\n", "\n", "(es decir, a la aplicación de la lista de transformaciones elementales\n", "de las filas sobre las filas de la matriz identidad $\\Mat{I}$)" ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccc}1&0&0\\\\1&2&0\\\\1&2&3\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([1, 1, 1]), Vector([0, 2, 2]), Vector([0, 0, 3])])" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "F = T(pfc[0]) & I(3)\n", "F" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "y por otra llamamos $\\Mat{B}$ al producto de matrices elementales\n", "\n", "`I(3) & T(pfc[1])`\n", "\n", "(correspondiente a las transformaciones realizadas sobre las columnas)" ] }, { "cell_type": "code", "execution_count": 34, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccc}\\frac{1}{2}&\\frac{1}{6}&\\frac{1}{12}\\\\0&\\frac{1}{3}&\\frac{1}{6}\\\\0&0&\\frac{1}{4}\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([1/2, 0, 0]), Vector([1/6, 1/3, 0]), Vector([1/12, 1/6, 1/4])])" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "C = I(3) & T(pfc[1])\n", "C" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "Tenemos que $\\Mat{FBC}$ es lo mismo que la transformación `T(pfc[0]) &\n", "Matrix(B) & T(pfc[1])` de más arriba, y que por tanto tiene que ser\n", "igual a la matriz identidad:" ] }, { "cell_type": "code", "execution_count": 35, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccc}1&0&0\\\\0&1&0\\\\0&0&1\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([1, 0, 0]), Vector([0, 1, 0]), Vector([0, 0, 1])])" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "F*B*C" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "Como $\\Mat{C}$ es invertible (por ser producto\n", "de elementales), tenemos que (multiplicando ambos lados de la igualdad por $\\Mat{C}$ por la\n", "izquierda y por $\\Mat{C}^{-1}$ por la derecha)\n", "\n", "$$\n", "\\Mat{F}\\Mat{B}\\Mat{C}=\\Mat{I}\n", "\\quad\\Rightarrow\\quad\n", "\\Mat{C}\\Mat{F}\\Mat{B}\\Mat{C}\\Mat{C}^{-1}=\\Mat{C}\\Mat{I}\\Mat{C}^{-1}\n", "\\quad\\Rightarrow\\quad\n", "\\Mat{C}\\Mat{F}\\Mat{B}=\\Mat{I}\n", "$$\n", "\n", "es decir, que $\\Mat{C}\\Mat{F}$ es la inversa de $\\Mat{B}$. Veámoslo:" ] }, { "cell_type": "code", "execution_count": 36, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccc}1&0&0\\\\0&1&0\\\\0&0&1\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([1, 0, 0]), Vector([0, 1, 0]), Vector([0, 0, 1])])" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(C*F) * B" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "es decir, que la inversa es el producto de las siguientes matrices\n", "(donde `A.m` y `A.n` deben ser iguales, pues la matriz debe ser\n", "cuadrada)" ] }, { "cell_type": "code", "execution_count": 37, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccc}\\frac{3}{4}&\\frac{1}{2}&\\frac{1}{4}\\\\\\frac{1}{2}&1&\\frac{1}{2}\\\\\\frac{1}{4}&\\frac{1}{2}&\\frac{3}{4}\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([3/4, 1/2, 1/4]), Vector([1/2, 1, 1/2]), Vector([1/4, 1/2, 3/4])])" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "( I(B.n) & T(pfc[1]) ) * ( T(pfc[0]) & I(B.m) )" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "Este extraño procedimiento está implementado en `InversaFC`, pero a\n", "diferencia de los anteriores, tras operar no vemos la matriz inversa.\n", "Para obtenerla es necesario multiplicar la matriz que queda debajo\n", "($\\Mat{C}$, correspondiente a las transformaciones de las columnas) por la matriz\n", "de la derecha ($\\Mat{F}$, correspondiente a las transformaciones de las filas)." ] }, { "cell_type": "code", "execution_count": 38, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/latex": [ "$\\displaystyle \\left[ \\begin{array}{ccc|ccc}2&-1&0&1&0&0\\\\-1&2&-1&0&1&0\\\\0&-1&2&0&0&1\\\\ \\hline 1&0&0&0&0&0\\\\0&1&0&0&0&0\\\\0&0&1&0&0&0\\\\ \\end{array} \\right]\\xrightarrow[\\underset{\\begin{subarray}{c} \\left[\\left(1\\right)\\mathbf{1}+\\mathbf{2} \\right]\\\\\\left[\\left(2\\right)\\mathbf{2}\\right]\\end{subarray}}{\\pmb{\\tau}}]{}\\left[ \\begin{array}{ccc|ccc}2&-1&0&1&0&0\\\\0&3&-2&1&2&0\\\\0&-1&2&0&0&1\\\\ \\hline 1&0&0&0&0&0\\\\0&1&0&0&0&0\\\\0&0&1&0&0&0\\\\ \\end{array} \\right]\\xrightarrow[\\underset{\\begin{subarray}{c} \\left[\\left(1\\right)\\mathbf{2}+\\mathbf{3} \\right]\\\\\\left[\\left(3\\right)\\mathbf{3}\\right]\\end{subarray}}{\\pmb{\\tau}}]{}\\left[ \\begin{array}{ccc|ccc}2&-1&0&1&0&0\\\\0&3&-2&1&2&0\\\\0&0&4&1&2&3\\\\ \\hline 1&0&0&0&0&0\\\\0&1&0&0&0&0\\\\0&0&1&0&0&0\\\\ \\end{array} \\right]\\xrightarrow{\\underset{\\begin{subarray}{c} \\left[\\left(2\\right)\\mathbf{2}\\right]\\\\\\left[\\left(1\\right)\\mathbf{1}+\\mathbf{2} \\right]\\end{subarray}}{\\pmb{\\tau}}}\\left[ \\begin{array}{ccc|ccc}2&0&0&1&0&0\\\\0&6&-2&1&2&0\\\\0&0&4&1&2&3\\\\ \\hline 1&1&0&0&0&0\\\\0&2&0&0&0&0\\\\0&0&1&0&0&0\\\\ \\end{array} \\right]\\xrightarrow{\\underset{\\begin{subarray}{c} \\left[\\left(3\\right)\\mathbf{3}\\right]\\\\\\left[\\left(1\\right)\\mathbf{2}+\\mathbf{3} \\right]\\end{subarray}}{\\pmb{\\tau}}}\\left[ \\begin{array}{ccc|ccc}2&0&0&1&0&0\\\\0&6&0&1&2&0\\\\0&0&12&1&2&3\\\\ \\hline 1&1&1&0&0&0\\\\0&2&2&0&0&0\\\\0&0&3&0&0&0\\\\ \\end{array} \\right]\\xrightarrow{\\underset{\\begin{subarray}{c} \\left[\\left(\\frac{1}{2}\\right)\\mathbf{1}\\right]\\\\\\left[\\left(\\frac{1}{6}\\right)\\mathbf{2}\\right]\\\\\\left[\\left(\\frac{1}{12}\\right)\\mathbf{3}\\right]\\end{subarray}}{\\pmb{\\tau}}}\\left[ \\begin{array}{ccc|ccc}1&0&0&1&0&0\\\\0&1&0&1&2&0\\\\0&0&1&1&2&3\\\\ \\hline \\frac{1}{2}&\\frac{1}{6}&\\frac{1}{12}&0&0&0\\\\0&\\frac{1}{3}&\\frac{1}{6}&0&0&0\\\\0&0&\\frac{1}{4}&0&0&0\\\\ \\end{array} \\right]$" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccc}\\frac{3}{4}&\\frac{1}{2}&\\frac{1}{4}\\\\\\frac{1}{2}&1&\\frac{1}{2}\\\\\\frac{1}{4}&\\frac{1}{2}&\\frac{3}{4}\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([3/4, 1/2, 1/4]), Vector([1/2, 1, 1/2]), Vector([1/4, 1/2, 3/4])])" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "InvMatFC(B,1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Si tan solo queremos la matriz inversa (sin mirar los pasos empleados para obtenerla), lo podemos hacer con `**`, que calcula potencias de una matriz cuadrada. Cuando el exponente es `-1`, este método literalmente transforma la matriz en $\\Mat{I}$ mediante una secuencia de transformaciones elementales que luego aplica a la $\\Mat{I}$ para obtener la matriz inversa." ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccc}\\frac{3}{4}&\\frac{1}{2}&\\frac{1}{4}\\\\\\frac{1}{2}&1&\\frac{1}{2}\\\\\\frac{1}{4}&\\frac{1}{2}&\\frac{3}{4}\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([3/4, 1/2, 1/4]), Vector([1/2, 1, 1/2]), Vector([1/4, 1/2, 3/4])])" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "B**(-1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Con `**` podemos calcular otras potencias, como el cuadrado de la inversa." ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccc}\\frac{7}{8}&1&\\frac{5}{8}\\\\1&\\frac{3}{2}&1\\\\\\frac{5}{8}&1&\\frac{7}{8}\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([7/8, 1, 5/8]), Vector([1, 3/2, 1]), Vector([5/8, 1, 7/8])])" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "B**(-2)" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "data": { "text/html": [ "

$\\left[ \\begin{array}{ccc}1&0&0\\\\0&1&0\\\\0&0&1\\\\ \\end{array} \\right]$

" ], "text/plain": [ "Matrix([Vector([1, 0, 0]), Vector([0, 1, 0]), Vector([0, 0, 1])])" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "B*B*(B**(-2))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Si la matriz no es cuadrada, o si es sigular, intentar calcular la matriz inversa arroja un mensaje de error" ] }, { "cell_type": "markdown", "metadata": { "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "source": [ "\n", "---- FIN DE LA LECCIÓN -----\n", "\n", "\n", "\n", "Lo que sigue es sólo para crear un índice de contenidos de este notebook (y se muestra al principio de la página)" ] }, { "cell_type": "code", "execution_count": 42, "metadata": { "autoscroll": false, "ein.hycell": false, "ein.tags": "worksheet-0", "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "application/javascript": [ "$.getScript('https://kmahelona.github.io/ipython_notebook_goodies/ipython_notebook_toc.js')\n", "$.getScript('https://kmahelona.github.io/ipython_notebook_goodies/ipython_notebook_toc.js')\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%javascript\n", "$.getScript('https://kmahelona.github.io/ipython_notebook_goodies/ipython_notebook_toc.js')\n", "$.getScript('https://kmahelona.github.io/ipython_notebook_goodies/ipython_notebook_toc.js')" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.2" }, "name": "Leccion05.ipynb" }, "nbformat": 4, "nbformat_minor": 2 }