Author: Marcos Bujosa
from nacal import *
$ \newcommand{\Rr}{{\mathbb{R}}} \newcommand{\Zz}{{\mathbb{Z}}} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \newcommand{\getItem}{\pmb{\mid}} \newcommand{\getitemR}[1]{\getItem{#1}} \newcommand{\getitemL}[1]{{#1}\getItem} \newcommand{\elemR}[2]{{#1}^{\phantom{\T}}_{\getitemR{#2}}} \newcommand{\elemRP}[2]{{\big(#1\big)}^{\phantom{\T}}_{\getitemR{#2}}} \newcommand{\elemRPE}[2]{\big({#1}^{\phantom{\T}}_{\getitemR{#2}}\big)} \newcommand{\elemL}[2]{ {_{\getitemL{#2}}#1} } \newcommand{\elemLP}[2]{ {_{\getitemL{#2}}\left(#1\right)} } \newcommand{\elemLPE}[2]{\left( {_{\getitemL{#2}}#1} \right)} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \newcommand{\Vect}[2][{}]{{\boldsymbol{#2}}_{#1}} \newcommand{\eleVR}[2] {\elemR {\Vect{#1}}{#2}} % con subindices \newcommand{\eleVRP}[2] {\elemRP {\Vect{#1}}{#2}} % con subindices y paréntesis interior \newcommand{\eleVRPE}[2]{\elemRPE{\Vect{#1}}{#2}} % con subindices y paréntesis exterior %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \newcommand{\VectC}[2][{}] {\elemR {\Mat{#2}}{#1}} % con subindices \newcommand{\VectCP}[2][{}] {\elemRP {\Mat{#2}}{#1}} % con subindices y paréntesis \newcommand{\VectCPE}[2][{}]{\elemRPE{\Mat{#1}}{#2}} % con subindices y paréntesis exterior \newcommand{\VectF}[2] {\elemL{\Mat{#1}}{#2}} % con subindices \newcommand{\VectFP}[2] {\elemL{(\Mat{#1})}{#2}} % con subindices y paréntesis \newcommand{\VectFPE}[2] {\elemLPE{\Mat{#1}}{#2}} % con subindices y paréntesis exterior %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \newcommand{\mat}[1]{\boldsymbol{\mathsf{#1}}} \newcommand{\Mat} [2][{}]{{\mat{#2}}_{#1}} \newcommand{\T}{\intercal} \newcommand{\MatT}[2][{}]{{\mat{#2}}^{\T}_{#1}} \newcommand{\VectCC}[2][{}] {\elemRR {\Mat{#2}}{#1}} % con () \newcommand{\VectCCC}[2][{}] {\elemRRR{\Mat{#2}}{#1}} % con texto "col" %SELECCIÓNA de FILAS y COlUMNAS DE UNA MATRIZ TRANSPUESTA PARA GENERAR UN VECTOR DE Rn \newcommand{\VectTC}[2][{}] {\elemR{\MatT{#2}\!}{#1}} % con subindices \newcommand{\VectTCC}[2][{}] {\elemRR{ \MatT{#2}}{#1}} % con () \newcommand{\VectTCCC}[2][{}] {\elemRRR{\MatT{#2}}{#1}} % con texto "col" \newcommand{\dotprod}[2][{}] {\Vect{#1}\cdot\Vect{#2}} $
Definimos una matriz (en esta ocasión fila a fila)
A = Matrix([[2,-1,0],[-1,2,-1],[0,-1,2]])
A
$\left[ \begin{array}{ccc}2&-1&0\\-1&2&-1\\0&-1&2\\ \end{array} \right]$
Calculemos su inversa mediante eliminación por columnas de izquierda a derecha. Para ello pongamos la matriz identidad de orden 3 a su derecha
Aampliada = A.concatena(I(3),1)
Aampliada
$\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]$
Y ahora apliquemos la elimnación
A.inversa(1)
$\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]$