feat: Add lua script for matrix product representation

This commit is contained in:
Samuel Ortion 2023-09-27 08:40:51 +02:00
parent 180409edc3
commit b7f323419d
11 changed files with 1151 additions and 56 deletions

1
.gitattributes vendored Normal file
View File

@ -0,0 +1 @@
main.pdf filter=lfs diff=lfs merge=lfs -text

View File

@ -1,34 +1,22 @@
\chapter{Linear Model}
\section{Generalized Linear Model}
\section{Simple Linear Regression}
\[
g(\EE(Y)) = X \beta
Y_i = \beta_0 + \beta_1 X_i + \varepsilon_i
\]
with $g$ being
\begin{itemize}
\item Logistic regression: $g(v) = \log \left(\frac{v}{1-v}\right)$, for instance for boolean values,
\item Poission regression: $g(v) = \log(v)$, for instance for discrete variables.
\end{itemize}
\subsection{Penalized Regression}
When the number of variables is large, e.g, when the number of explanatory variable is above the number of observations, if $p >> n$ ($p$: the number of explanatory variable, $n$ is the number of observations), we cannot estimate the parameters.
In order to estimate the parameters, we can use penalties (additional terms).
Lasso regression, Elastic Net, etc.
\subsection{Simple Linear Model}
\begin{align*}
\Y &= \X \beta + \varepsilon \\
\[
\Y = \X \beta + \varepsilon.
\]
\[
\begin{pmatrix}
Y_1 \\
Y_2 \\
\vdots \\
Y_n
\end{pmatrix}
&= \begin{pmatrix}
=
\begin{pmatrix}
1 & X_1 \\
1 & X_2 \\
\vdots & \vdots \\
@ -42,17 +30,35 @@ Lasso regression, Elastic Net, etc.
\begin{pmatrix}
\varepsilon_1 \\
\varepsilon_2 \\
\vdots \\
\vdots
\varepsilon_n
\end{pmatrix}
\end{align*}
\]
\subsection{Assumptions}
\paragraph*{Assumptions}
\begin{enumerate}[label={\color{primary}{($A_\arabic*$)}}]
\item $\varepsilon_i$ are independent;
\item $\varepsilon_i$ are identically distributed;
\item $\varepsilon_i$ are i.i.d $\sim \Norm(0, \sigma^2)$ (homoscedasticity).
\end{enumerate}
\section{Generalized Linear Model}
\[
g(\EE(Y)) = X \beta
\]
with $g$ being
\begin{itemize}
\item
\item Logistic regression: $g(v) = \log \left(\frac{v}{1-v}\right)$, for instance for boolean values,
\item Poisson regression: $g(v) = \log(v)$, for instance for discrete variables.
\end{itemize}
\subsection{Penalized Regression}
When the number of variables is large, e.g, when the number of explanatory variable is above the number of observations, if $p >> n$ ($p$: the number of explanatory variable, $n$ is the number of observations), we cannot estimate the parameters.
In order to estimate the parameters, we can use penalties (additional terms).
Lasso regression, Elastic Net, etc.
\subsection{Statistical Analysis Workflow}
@ -95,9 +101,9 @@ is noted equivalently as
\subsection{General Case}
If $\X^\T\X$ is invertible, the OLS estimator is:
If $\X^T\X$ is invertible, the OLS estimator is:
\begin{equation}
\hat{\beta} = (\X^\T\X)^{-1} \X^\T \Y
\hat{\beta} = (\X^T\X)^{-1} \X^T \Y
\end{equation}
\subsection{Ordinary Least Square Algorithm}
@ -112,12 +118,12 @@ We want to minimize the distance between $\X\beta$ and $\Y$:
\Rightarrow& \forall v \in w,\, vy = v proj^w(y)\\
\Rightarrow& \forall i: \\
& \X_i \Y = \X_i X\hat{\beta} \qquad \text{where $\hat{\beta}$ is the estimator of $\beta$} \\
\Rightarrow& \X^\T \Y = \X^\T \X \hat{\beta} \\
\Rightarrow& {\color{gray}(\X^\T \X)^{-1}} \X^\T \Y = {\color{gray}(\X^\T \X)^{-1}} (\X^\T\X) \hat{\beta} \\
\Rightarrow& \hat{\beta} = (X^\T\X)^{-1} \X^\T \Y
\Rightarrow& \X^T \Y = \X^T \X \hat{\beta} \\
\Rightarrow& {\color{gray}(\X^T \X)^{-1}} \X^T \Y = {\color{gray}(\X^T \X)^{-1}} (\X^T\X) \hat{\beta} \\
\Rightarrow& \hat{\beta} = (\X^T\X)^{-1} \X^T \Y
\end{align*}
This formula comes from the orthogonal projection of $\Y$ on the subspace define by the explanatory variables $\X$
This formula comes from the orthogonal projection of $\Y$ on the vector subspace defined by the explanatory variables $\X$
$\X \hat{\beta}$ is the closest point to $\Y$ in the subspace generated by $\X$.

View File

@ -31,12 +31,12 @@ Let $u = \begin{pmatrix}
We may use $\scalar{u, v}$ or $u \cdot v$ notations.
\end{definition}
\paragraph{Dot product properties}
\begin{itemize}
\item $\scalar{u, v} = \scalar{v, u}$
\item $\scalar{(u+v), w} = \scalar{u, w} + \scalar{v, w}$
\item $\scalar{u, v}$
\item $\scalar{\vec{u}, \vec{v}} = \norm{\vec{u}} \times \norm{\vec{v}} \times \cos(\widehat{\vec{u}, \vec{v}})$
\end{itemize}
\begin{description}
\item[Commutative] $\scalar{u, v} = \scalar{v, u}$
\item[Distributive] $\scalar{(u+v), w} = \scalar{u, w} + \scalar{v, w}$
\item $\scalar{u, v} = \norm{u} \times \norm{v} \times \cos(\widehat{u, v})$
\item $\scalar{a, a} = \norm{a}^2$
\end{description}
\begin{definition}[Norm]
Length of the vector.
@ -99,7 +99,7 @@ Let $u = \begin{pmatrix}
\end{align*}
\end{proof}
\begin{theorem}{Pythagorean theorem}
\begin{theorem}[Pythagorean theorem]
If $u \perp v$, then $\norm{u+v}^2 = \norm{u}^2 + \norm{v}^2$ .
\end{theorem}
@ -110,7 +110,7 @@ Let $y = \begin{pmatrix}
y_1 \\
. \\
y_n
\end{pmatrix} \in \RR[n]$ and $w$ a subspace of $\RR[n]$
\end{pmatrix} \in \RR[n]$ and $w$ a subspace of $\RR[n]$.
$\mathcal{Y}$ can be written as the orthogonal projection of $y$ on $w$:
\[
\mathcal{Y} = proj^w(y) + z,
@ -178,9 +178,26 @@ The scalar product between $z$ and (?) is zero.
x_3 \\
x_4
\end{pmatrix}
& = \begin{pmatrix}
a x_1 + b x_2 + c x_3 \ldots
\end{pmatrix}
=
\begin{pmatrix}
\luadirect{
local matrix_product = require("scripts.matrix_product")
local m1 = {
{"a", "b", "c", "d"},
{"e", "f", "g", "h"},
{"i", "j", "k", "l"}
}
local m2 = {
{"x_1"},
{"x_2"},
{"x_3"},
{"x_4"}
}
local product_matrix = matrix_product.matrix_product_repr(m1,m2)
local matrix_dump = matrix_product.dump_matrix(product_matrix)
tex.print(matrix_dump)
}
\end{pmatrix}
\end{align*}
\end{example}
@ -190,7 +207,7 @@ The number of columns has to be the same as the dimension of the vector to which
Let $A = \begin{pmatrix}
a & b \\
c & d
\end{pmatrix}$, then $A^\T = \begin{pmatrix}
\end{pmatrix}$, then $A^T = \begin{pmatrix}
a & c \\
b & d
\end{pmatrix}$

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

View File

@ -0,0 +1,988 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
width="175.798"
height="170.477"
viewBox="0 0 175.798 170.477"
version="1.1"
id="svg88"
sodipodi:docname="ordinary_least_squares.svg"
inkscape:export-filename="ordinary_least_squares.png"
inkscape:export-xdpi="300"
inkscape:export-ydpi="300"
inkscape:version="1.3 (0e150ed6c4, 2023-07-21)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<sodipodi:namedview
id="namedview88"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
inkscape:export-bgcolor="#ffffffff"
inkscape:zoom="3.7372438"
inkscape:cx="87.899002"
inkscape:cy="85.223233"
inkscape:window-width="1920"
inkscape:window-height="1011"
inkscape:window-x="0"
inkscape:window-y="32"
inkscape:window-maximized="1"
inkscape:current-layer="svg88" />
<defs
id="defs1">
<g
id="g1">
<g
id="glyph-0-0" />
<g
id="glyph-0-1">
<path
d="M 1.90625 -0.53125 C 1.90625 -0.8125 1.671875 -1.0625 1.390625 -1.0625 C 1.09375 -1.0625 0.859375 -0.8125 0.859375 -0.53125 C 0.859375 -0.234375 1.09375 0 1.390625 0 C 1.671875 0 1.90625 -0.234375 1.90625 -0.53125 Z M 1.90625 -0.53125 "
id="path1" />
</g>
</g>
</defs>
<path
fill="none"
stroke-width="0.3985"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(0%, 0%, 0%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 0.00165625 -0.00046875 L 141.275094 -0.00046875 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path2" />
<path
fill="none"
stroke-width="0.31879"
stroke-linecap="round"
stroke-linejoin="round"
stroke="rgb(0%, 0%, 0%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M -1.195979 1.593281 C -1.094416 0.995625 -0.00066625 0.101094 0.300115 -0.00046875 C -0.00066625 -0.098125 -1.094416 -0.996563 -1.195979 -1.594219 "
transform="matrix(1, 0, 0, -1, 156.62176, 156.105)"
id="path3" />
<path
fill="none"
stroke-width="0.3985"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(0%, 0%, 0%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 0.00165625 -0.00046875 L 0.00165625 141.276875 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path4" />
<path
fill="none"
stroke-width="0.31879"
stroke-linecap="round"
stroke-linejoin="round"
stroke="rgb(0%, 0%, 0%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M -1.194197 1.592094 C -1.096541 0.994438 0.001115 0.0999063 0.29799 -0.00165625 C 0.001115 -0.0993125 -1.096541 -0.99775 -1.194197 -1.595406 "
transform="matrix(0, -1, -1, 0, 15.346, 14.82924)"
id="path5" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 46.767281 66.046406 L 46.767281 76.855 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path6" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 59.880562 68.671406 L 59.880562 52.015156 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path7" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 35.450875 63.784687 L 35.450875 71.526875 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path8" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 122.404 81.175312 L 122.404 69.929219 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path9" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 3.532906 57.401875 L 3.532906 49.745625 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path10" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 108.482125 78.390156 L 108.482125 68.062031 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path11" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 19.236031 60.5425 L 19.236031 38.245625 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path12" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 107.814156 78.257344 L 107.814156 54.538594 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path13" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 78.087594 72.312031 L 78.087594 75.976094 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path14" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 105.345406 77.76125 L 105.345406 105.07375 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path15" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 31.017281 62.897969 L 31.017281 60.312031 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path16" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 73.509469 71.394062 L 73.509469 75.581562 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path17" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 78.696969 72.433125 L 78.696969 85.390156 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path18" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 89.134469 74.519062 L 89.134469 91.308125 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path19" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 82.732125 73.241719 L 82.732125 60.472187 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path20" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 117.583687 80.210469 L 117.583687 103.663594 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path21" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 136.829781 84.058125 L 136.829781 70.003437 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path22" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 17.001656 60.093281 L 17.001656 43.964375 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path23" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 125.950875 81.882344 L 125.950875 109.300312 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path24" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 73.302437 71.355 L 73.302437 94.800312 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path25" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 49.404 66.57375 L 49.404 54.245625 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path26" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 32.802437 63.253437 L 32.802437 62.362812 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path27" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 55.177437 67.73 L 55.177437 95.628437 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path28" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 80.2165 72.737812 L 80.2165 97.69875 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path29" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 78.911812 72.476094 L 78.911812 61.659687 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path30" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 130.681344 82.831562 L 130.681344 98.456562 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path31" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 108.232125 78.339375 L 108.232125 74.976094 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path32" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 49.529 66.601094 L 49.529 56.327656 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path33" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 23.986031 61.491719 L 23.986031 88.608906 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path34" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 16.298531 59.952656 L 16.298531 74.2925 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path35" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 35.868844 63.866719 L 35.868844 89.07375 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path36" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 94.482125 75.589375 L 94.482125 59.628437 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path37" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 27.876656 62.269062 L 27.876656 78.515156 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path38" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 61.513375 68.995625 L 61.513375 45.487812 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path39" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 109.154 78.522969 L 109.154 104.105 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path40" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 141.575875 85.007344 L 141.575875 63.390156 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path41" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 33.134469 63.319844 L 33.134469 48.030781 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path42" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 85.462594 73.784687 L 85.462594 80.765156 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path43" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 31.521187 62.999531 L 31.521187 44.23 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path44" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 79.845406 72.663594 L 79.845406 88.487812 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path45" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 67.775094 70.249531 L 67.775094 69.421406 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path46" />
<path
fill="none"
stroke-width="0.19925"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(75%, 75%, 75%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 78.626656 72.4175 L 78.626656 57.780781 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path47" />
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g47">
<use
xlink:href="#glyph-0-1"
x="60.728"
y="79.778"
id="use47" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g48">
<use
xlink:href="#glyph-0-1"
x="73.841"
y="104.616"
id="use48" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g49">
<use
xlink:href="#glyph-0-1"
x="49.412"
y="85.108"
id="use49" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g50">
<use
xlink:href="#glyph-0-1"
x="136.364"
y="86.704"
id="use50" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g51">
<use
xlink:href="#glyph-0-1"
x="17.494"
y="106.887"
id="use51" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g52">
<use
xlink:href="#glyph-0-1"
x="122.44"
y="88.57"
id="use52" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g53">
<use
xlink:href="#glyph-0-1"
x="33.198"
y="118.387"
id="use53" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g54">
<use
xlink:href="#glyph-0-1"
x="121.773"
y="102.094"
id="use54" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g55">
<use
xlink:href="#glyph-0-1"
x="92.049"
y="80.656"
id="use55" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g56">
<use
xlink:href="#glyph-0-1"
x="119.307"
y="51.558"
id="use56" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g57">
<use
xlink:href="#glyph-0-1"
x="44.979"
y="96.322"
id="use57" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g58">
<use
xlink:href="#glyph-0-1"
x="87.471"
y="81.051"
id="use58" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g59">
<use
xlink:href="#glyph-0-1"
x="92.655"
y="71.244"
id="use59" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g60">
<use
xlink:href="#glyph-0-1"
x="103.093"
y="65.325"
id="use60" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g61">
<use
xlink:href="#glyph-0-1"
x="96.693"
y="96.162"
id="use61" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g62">
<use
xlink:href="#glyph-0-1"
x="131.542"
y="52.971"
id="use62" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g63">
<use
xlink:href="#glyph-0-1"
x="150.79"
y="86.629"
id="use63" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g64">
<use
xlink:href="#glyph-0-1"
x="30.961"
y="112.667"
id="use64" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g65">
<use
xlink:href="#glyph-0-1"
x="139.911"
y="47.335"
id="use65" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g66">
<use
xlink:href="#glyph-0-1"
x="87.263"
y="61.833"
id="use66" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g67">
<use
xlink:href="#glyph-0-1"
x="63.363"
y="102.386"
id="use67" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g68">
<use
xlink:href="#glyph-0-1"
x="46.762"
y="94.27"
id="use68" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g69">
<use
xlink:href="#glyph-0-1"
x="69.139"
y="61.006"
id="use69" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g70">
<use
xlink:href="#glyph-0-1"
x="94.176"
y="58.936"
id="use70" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g71">
<use
xlink:href="#glyph-0-1"
x="92.871"
y="94.973"
id="use71" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g72">
<use
xlink:href="#glyph-0-1"
x="144.642"
y="58.179"
id="use72" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g73">
<use
xlink:href="#glyph-0-1"
x="122.192"
y="81.657"
id="use73" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g74">
<use
xlink:href="#glyph-0-1"
x="63.488"
y="100.304"
id="use74" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g75">
<use
xlink:href="#glyph-0-1"
x="37.946"
y="68.026"
id="use75" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g76">
<use
xlink:href="#glyph-0-1"
x="30.259"
y="82.34"
id="use76" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g77">
<use
xlink:href="#glyph-0-1"
x="49.831"
y="67.561"
id="use77" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g78">
<use
xlink:href="#glyph-0-1"
x="108.444"
y="97.003"
id="use78" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g79">
<use
xlink:href="#glyph-0-1"
x="41.836"
y="78.118"
id="use79" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g80">
<use
xlink:href="#glyph-0-1"
x="75.475"
y="111.147"
id="use80" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g81">
<use
xlink:href="#glyph-0-1"
x="123.115"
y="52.529"
id="use81" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g82">
<use
xlink:href="#glyph-0-1"
x="155.535"
y="93.242"
id="use82" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g83">
<use
xlink:href="#glyph-0-1"
x="47.094"
y="108.603"
id="use83" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g84">
<use
xlink:href="#glyph-0-1"
x="99.424"
y="75.869"
id="use84" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g85">
<use
xlink:href="#glyph-0-1"
x="45.483"
y="112.404"
id="use85" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g86">
<use
xlink:href="#glyph-0-1"
x="93.806"
y="68.145"
id="use86" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g87">
<use
xlink:href="#glyph-0-1"
x="81.735"
y="87.214"
id="use87" />
</g>
<g
fill="rgb(0%, 0%, 0%)"
fill-opacity="1"
id="g88">
<use
xlink:href="#glyph-0-1"
x="92.588"
y="98.852"
id="use88" />
</g>
<path
fill="none"
stroke-width="0.79701"
stroke-linecap="butt"
stroke-linejoin="miter"
stroke="rgb(0%, 0%, 100%)"
stroke-opacity="1"
stroke-miterlimit="10"
d="M 0.00165625 56.694844 L 141.732125 85.038594 "
transform="matrix(1, 0, 0, -1, 15.346, 156.105)"
id="path88" />
</svg>

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

View File

@ -0,0 +1,26 @@
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\begin{document}
\tdplotsetmaincoords{105}{-30}
\usetikzlibrary{patterns}
\begin{tikzpicture}[tdplot_main_coords,font=\sffamily]
\tdplotsetrotatedcoords{00}{30}{0}
\begin{scope}[tdplot_rotated_coords]
\begin{scope}[canvas is xy plane at z=0]
\draw[fill opacity=0,pattern=north west lines,pattern color=gray] (-2,-3) rectangle (2,3);
\draw[gray,fill=lightgray,fill opacity=0.75] (-2,-3) rectangle (2,3);
\draw[very thick] (-2,0) -- (2,0);
\path (-150:2) coordinate (H) (-1.5,0) coordinate(X);
\pgflowlevelsynccm
\draw[very thick,-stealth,gray] (0,0) -- (-30:1.5);
\end{scope}
\draw[stealth-] (H) -- ++ (-1,0,0.2) node[pos=1.3]{$H$};
\draw[stealth-] (X) -- ++ (0,1,0.2) node[pos=1.3]{$X$};
\draw[very thick,-stealth] (0,0,0) coordinate (O) -- (0,0,3) node[right]{$p$};
\end{scope}
\pgfmathsetmacro{\Radius}{1.5}
\draw[-stealth] (O)-- (2.5*\Radius,0,0) node[pos=1.15] {$x$};
\draw[-stealth] (O) -- (0,3.5*\Radius,0) node[pos=1.15] {$z$};
\draw[-stealth] (O) -- (0,0,2.5*\Radius) node[pos=1.05] {$y$};
\end{tikzpicture}
\end{document}

BIN
main.pdf

Binary file not shown.

View File

@ -3,4 +3,4 @@
\usepackage{standalone}
\usepackage{tikz-3dplot}
\usepackage{tkz-euclide}
\usepackage{mathtools}
\usepackage{nicematrix}

View File

@ -0,0 +1,57 @@
local function matrix_product_repr(m1, m2)
if #m1[1] ~= #m2 then -- inner matrix-dimensions must agree
return nil
end
local res = {}
for i = 1, #m1 do
res[i] = {}
for j = 1, #m2[1] do
res[i][j] = " "
for k = 1, #m2 do
if k ~= 1 then
res[i][j] = res[i][j] .. " + "
end
res[i][j] = res[i][j] .. m1[i][k] .. " " .. m2[k][j]
end
end
end
return res
end
local function dump_matrix(matrix)
local repr = ""
for i, row in ipairs(matrix) do
for j, cell in ipairs(row) do
repr = repr .. " " .. cell
if j ~= #row then
repr = repr .. " & "
end
end
if i ~= #matrix then
repr = repr .. [[ \\ ]]
end
repr = repr .. "\n"
end
return repr
end
local m1 = {
{"a", "b", "c", "d"},
{"e", "f", "g", "h"},
{"i", "j", "k", "l"}
}
local m2 = {
{"x_1"},
{"x_2"},
{"x_3"},
{"x_4"}
}
print(dump_matrix(matrix_product_repr(m1, m2)))
return {
matrix_product_repr = matrix_product_repr,
dump_matrix = dump_matrix
}