\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[english,spanish]{babel}
\decimalpoint
\unaccentedoperators
\usepackage[bookmarks=false,colorlinks = true,linkcolor = blue,urlcolor  = blue,citecolor = blue,anchorcolor = blue]{hyperref}

\usepackage[intlimits]{amsmath}
\usepackage{amsfonts,amssymb,amsthm,extarrows}
\usepackage[width=16cm,height=21cm]{geometry}
\usepackage{graphicx}
\usepackage{tikz}
\usepackage{ifthen}
\usepackage{enumerate}
\usepackage{colortbl}

\theoremstyle{definition}
\newtheorem{example}{Ejemplo}
\newtheorem{defn}{Definición}
\newtheorem{algorithm}{Algoritmo}

\newcommand{\medstrut}{\ensuremath{\vphantom{\int_{0_0}^{1^1}}}}
\newcommand{\bigstrut}{\ensuremath{\vphantom{\displaystyle\int}}}

\newcommand{\IntegerNumbers}{{\mathbb{Z}}}
\newcommand{\RationalNumbers}{{\mathbb{Q}}}
\newcommand{\RealNumbers}{{\mathbb{R}}}
\newcommand{\ComplexNumbers}{{\mathbb{C}}}

\newcommand{\nullvector}{\boldsymbol{0}}
\renewcommand{\Re}{\mathop{\mathrm{Re}}\nolimits}
\renewcommand{\Im}{\mathop{\mathrm{Im}}\nolimits}
\renewcommand{\phi}{\varphi}
\newcommand{\eps}{\varepsilon}

\DeclareMathOperator{\diag}{diag}
\DeclareMathOperator{\tr}{tr}
\DeclareMathOperator{\rank}{r}
\DeclareMathOperator{\imagunit}{i}
\DeclareMathOperator{\enumber}{e}
\newcommand{\matr}[2]{\left[\begin{array}{#1}#2\end{array}\right]}
\newcommand{\Matrices}[3]{\mathcal{M}_{#2\times #3}(#1)}
\newcommand{\SquareRealMatrices}[1]{\mathcal{M}_{#1}(\RealNumbers)}
\newcommand{\markedcell}{\cellcolor[rgb]{0.7,1.0,0.7}}

\begin{document}
\begin{center}
\bfseries\large Matrices de Laplace--Dirichlet\\asociadas a las mallas rectangulares
\end{center}

\medskip\noindent
Estos apuntes están escritos por Daniel Hernández León, con ayuda de Egor Maximenko.


\subsection*{Ejemplo $\boldsymbol{2\times 3}$}

\medskip\noindent
Consideremos el problema de calor sobre una malla rectangular $2\times 3$ ($p=2$, $q=3$):
\begin{center}
\begin{tikzpicture}[scale=2]
\draw[black] (0,0) grid (2,1);
\foreach \j/\k/\n in {1/0/1, 1/1/2, 1/2/3, 0/0/4, 0/1/5, 0/2/6} {
  \filldraw (\k,\j) circle (0.2mm);
  \node[above left] at (\k,\j) {$x_\n$};
}
\foreach \k/\n in {0/1, 1/2} {
  \draw (-1,\k)--(0,\k);
  \filldraw (-1,\k) circle (0.2mm);
  \node[left] at (-1,\k) {$a_{\n}$};
}
\foreach \j/\n in {0/3, 1/4, 2/5} {
  \draw (\j,1)--(\j,2);
  \filldraw (\j,2) circle (0.2mm);
  \node[above] at (\j,2) {$a_{\n}$};
}
\foreach \k/\n in {1/6, 0/7} {
  \draw (2,\k)--(3,\k);
  \filldraw (3,\k) circle (0.2mm);
  \node[right] at (3,\k) {$a_{\n}$};
}
\foreach \j/\n in {2/8, 1/9, 0/10 } {
  \draw (\j,-1)--(\j,0);
  \filldraw (\j,-1) circle (0.2mm);
  \node[below] at (\j,-1) {$a_{\n}$};
}
\end{tikzpicture}
\end{center}
En cada uno de los nodos $x_j$ consideramos la ecuación discretizada de Laplace (la ecuación de calor).
Se busca una solución estancionaria, cuando los valores $x_j$ no dependen del tiempo.
Por ejemplo, en el nodo $x_1$ la ecuación será
\[
(x_1-a_2)+(x_1-a_3)+(x_1-x_2)+(x_1-x_4)=0.
\]
Los números $a_k$ están dados, y los pasamos al lado derecho de la ecuación:
\[
4x_1 -x_2 - x_4 = a_2 + a_3.
\]
Procediendo de esta manera obtenemos el siguiente sistema de ecuaciones
para las incógnitas $x_1,\ldots,x_6$:
\begin{align*}
4x_1 - x_2 - x_4 &= a_2 + a_3, \\
4x_2 - ??? &= ???, \\
4x_3 - ??? &= ???, \\
4x_4 - ??? &= ???, \\
4x_5 - ??? &= ???, \\
4x_6 - ??? &= ???.
\end{align*}
Este sistema de ecuaciones se puede escribir en forma matricial.
Ahora nos fijamos solamente en la matriz del sistema.
La matriz es cuadrada y de orden $n=6$:
\begin{equation}\label{matrix23}
A^{(2,3)}=
\matr{rrrrrr}{
4 & -1 & 0 & -1 & 0 & 0 \\
-1 & 4 & -1 & 0 & -1 & 0 \\
0 & -1 & 4 & 0 & 0 & -1 \\
? & ? & ? & ? & ? & ? \\
? & ? & ? & ? & ? & ? \\
? & ? & ? & ? & ? & ?
}.
\end{equation}
Para entender la construcción de la matriz,
es más cómodo fijarse no en los nodos de la malla, sino en las aristas.
Por ejemplo, la arista que une los nodos $x_1$ y $x_4$
corresponde a los sumandos $x_1-x_4$ en la primera ecuación
y a los sumandos $x_4-x_1$ en la cuarta ecuación.
En otras palabras, la arista $\{1,4\}$ hace la siguiente contribución a la matriz:
\[
\matr{rrrrrr}{
+1 & 0 & 0 & -1 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 \\
-1 & 0 & 0 & +1 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0
}.
\]
La arista $\{2,3\}$ hace la siguiente contribución a la matriz:
\[
\matr{rrrrrr}{
0 & 0 & 0 & 0 & 0 & 0 \\
0 & +1 & -1 & 0 & 0 & 0 \\
0 & -1 & +1 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0
}.
\]
La arista que une los nodos $x_1$ y $a_2$ hace la siguiente contribución a la matriz:
\[
\matr{rrrrrr}{
+1 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0 \\
0 & 0 & 0 & 0 & 0 & 0
}.
\]
Al sumar las matrices de esta forma que corresponden a todas las aristas, se obtiene \eqref{matrix23}.


\clearpage
\subsection*{Ejemplo $\boldsymbol{4\times 3}$}

\medskip\noindent
Para $p=4$ y $q=3$ la malla es
\begin{center}
(hay que copiar y modificar el dibujo anterior)
\end{center}
La matriz de Laplace--Dirichlet es
\begin{equation}\label{matrix43}
A^{(4,3)}=
\matr{rrrrrrrrrrrr}{
? & ? & ? & ? & ? & ? & ? & ? & ? & ? & ? & ? \\
? & ? & ? & ? & ? & ? & ? & ? & ? & ? & ? & ? \\
? & ? & ? & ? & ? & ? & ? & ? & ? & ? & ? & ? \\
? & ? & ? & ? & ? & ? & ? & ? & ? & ? & ? & ? \\
? & ? & ? & ? & ? & ? & ? & ? & ? & ? & ? & ? \\
? & ? & ? & ? & ? & ? & ? & ? & ? & ? & ? & ? \\
? & ? & ? & ? & ? & ? & ? & ? & ? & ? & ? & ? \\
? & ? & ? & ? & ? & ? & ? & ? & ? & ? & ? & ? \\
? & ? & ? & ? & ? & ? & ? & ? & ? & ? & ? & ? \\
? & ? & ? & ? & ? & ? & ? & ? & ? & ? & ? & ? \\
? & ? & ? & ? & ? & ? & ? & ? & ? & ? & ? & ? \\
? & ? & ? & ? & ? & ? & ? & ? & ? & ? & ? & ? 
}.
\end{equation}

\subsection*{Función que construye la matriz en el caso general $\boldsymbol{p\times q}$}

\begin{verbatim}
function [A] = rectangular_lattice(p, q),
   n = ???;
   A = zeros(n, n);
   ???
end
\end{verbatim}
Para $p=2$, $q=3$ la función regresa la matriz \eqref{matrix23},
y para $p=4$, $q=3$ la función regresa la matriz \eqref{matrix43}.



\end{document}
