Inscription / Connexion Nouveau Sujet
Niveau enseignement
Partager :

Code latex produit matriciel

Posté par
helocla69
01-03-23 à 16:35

Bonjour,

je suis à la recherche d'un code latex pour expliquer le produit matriciel (c'est une figure un peu compliquée et je ne vois pas où commencer) un peu comme celle présentée ici https://les-mathematiques.net/serveur_cours/cours/2/77/

Bonne journée

Bien cordialement

Posté par
Pirho
re : Code latex produit matriciel 01-03-23 à 17:22

Bonjour,

je ne sais pas si j'ai bien compris,mais voilà un exemple

\begin{pmatrix} 2 & 3 & 4 & 5 &10 \\ 5&4 &-6 &-6 &13 \\ 12&7 &8 &9 &14 \\ 0&-8 &3 &-4 &1 \\ -4&12 &-8 & 9&6 \end{pmatrix}

en cliquant sur LTX avec les 2 points rouge situé sous le cadre, tu pourras voir un peu les possibilités

Bon courage!

Posté par
Rintaro
re : Code latex produit matriciel 01-03-23 à 18:18

Bonjour à vous deux,

je pense que helocla69 souhaite annoter les matrices comme dans le lien fourni (section 2.3 - produit matriciel), et en effet c'est galère à faire en pur LaTeX.

Je propose un site : https://www.mathcha.io/editor, où l'on peut faire un peu tout ce qu'on veut pour les figures en LaTeX sans avoir besoin de se farcir du tikz en veux-tu en voilà, et ici je pense que ça fera largement l'affaire. Le site demande un peu d'habitude, mais il existe de nombreuses documentations.

Bonne journée à vous deux (et comme Pirho le souhaite, bon courage .)

Posté par
verdurin
re : Code latex produit matriciel 01-03-23 à 18:53

Bonsoir,
on peut facilement faire des choses comme ça :
\begin{array}{cc}
 \\ & \begin{pmatrix} 1&2\\3&4 \end{pmatrix}
 \\ 
 \\ \begin{pmatrix} 4&2\\3&1\end{pmatrix}&\begin{pmatrix} a&b\\c&d\end{pmatrix}
 \\ \end{array}

Pour les flèches, outre la proposition de Rintaro, il y a Tikz ou PSTricks ou l'utilisation d'un logiciel externe ( par exemple Inkscape ) pour modifier le PDF.

Posté par
verdurin
re : Code latex produit matriciel 01-03-23 à 19:01

J'ai oublié de mettre le code

\begin{array}{cc}
 & \begin{pmatrix}
   1&2\\3&4
  \end{pmatrix}
\\
  \begin{pmatrix}
   4&2\\3&1
  \end{pmatrix}
 &
  \begin{pmatrix}
   a&b\\c&d
  \end{pmatrix}
\end{array}

Ce n'est pas exactement celui que j'ai utilisé dans le message précédent car le \LaTeX du site a une gestion non conforme des espaces et des retours à la ligne.

Posté par
matheux14
re : Code latex produit matriciel 01-03-23 à 19:16

Salut, vous pouvez le faire avec tikz.

Vous verrez le code ainsi que le pdf par ici :

Posté par
hekla
re : Code latex produit matriciel 02-03-23 à 13:11

Bonjour

Connaissez-vous le package  nicematrix

sur ctan

la documentation est en français

Posté par
hekla
re : Code latex produit matriciel 02-03-23 à 17:17

un exemple montrant le produit  de matrices
le code



% Author : Alain Matthes
% Source : http://altermundus.com/pages/examples.html
\documentclass[]{article}

\usepackage[utf8]{inputenc}
\usepackage[upright]{fourier}
\usepackage{tikz}
\usetikzlibrary{matrix,arrows,decorations.pathmorphing}
\usepackage{verbatim}

\begin{comment}
:Title: Matrix multiplication
:Use page: 1

Illustration of how to compute the product of two matrices.

:Source: `Altermundus.com`_

.. _Altermundus.com: http://altermundus.com/pages/examples.html
\end{comment}

\begin{document}

% l' unite
\newcommand{\myunit}{1 cm}
\tikzset{
    node style sp/.style={draw,circle,minimum size=\myunit},
    node style ge/.style={circle,minimum size=\myunit},
    arrow style mul/.style={draw,sloped,midway,fill=white},
    arrow style plus/.style={midway,sloped,fill=white},
}

\begin{tikzpicture}[>=latex]
% les matrices
\matrix (A) [matrix of math nodes,
             nodes = {node style ge},
             left delimiter  = (,
             right delimiter = )] at (0,0)
{
  a_{11} & a_{12} & \ldots & a_{1p}  \\
  |[node style sp]| a_{21}
         & |[node style sp]| a_{22}
                  & \ldots
                           & |[node style sp]| a_{2p} \\
  \vdots & \vdots & \ddots & \vdots  \\
  a_{n1} & a_{n2} & \ldots & a_{np}  \\
};
\node [draw,below=10pt] at (A.south) 
    { $A$ : \textcolor{red}{$n$ rows} $p$ columns};

\matrix (B) [matrix of math nodes,
             nodes = {node style ge},
             left delimiter  = (,
             right delimiter = )] at (6*\myunit,6*\myunit)
{
  b_{11} & |[node style sp]| b_{12}
                  & \ldots & b_{1q}  \\
  b_{21} & |[node style sp]| b_{22}
                  & \ldots & b_{2q}  \\
  \vdots & \vdots & \ddots & \vdots  \\
  b_{p1} & |[node style sp]| b_{p2}
                  & \ldots & b_{pq}  \\
};
\node [draw,above=10pt] at (B.north) 
    { $B$ : $p$ rows \textcolor{red}{$q$ columns}};
% matrice résultat
\matrix (C) [matrix of math nodes,
             nodes = {node style ge},
             left delimiter  = (,
             right delimiter = )] at (6*\myunit,0)
{
  c_{11} & c_{12} & \ldots & c_{1q} \\
  c_{21} & |[node style sp,red]| c_{22}
                  & \ldots & c_{2q} \\
  \vdots & \vdots & \ddots & \vdots \\
  c_{n1} & c_{n2} & \ldots & c_{nq} \\
};
% les fleches
\draw[blue] (A-2-1.north) -- (C-2-2.north);
\draw[blue] (A-2-1.south) -- (C-2-2.south);
\draw[blue] (B-1-2.west)  -- (C-2-2.west);
\draw[blue] (B-1-2.east)  -- (C-2-2.east);
\draw[<->,red](A-2-1) to[in=180,out=90]
	node[arrow style mul] (x) {$a_{21}\times b_{12}$} (B-1-2);
\draw[<->,red](A-2-2) to[in=180,out=90]
	node[arrow style mul] (y) {$a_{22}\times b_{22}$} (B-2-2);
\draw[<->,red](A-2-4) to[in=180,out=90]
	node[arrow style mul] (z) {$a_{2p}\times b_{p2}$} (B-4-2);
\draw[red,->] (x) to node[arrow style plus] {$+$} (y)%
    to node[arrow style plus] {$+\raisebox{.5ex}{\ldots}+$} (z)
    to (C-2-2.north west);


\node [draw,below=10pt] at (C.south) 
    {$ C=A\times B$ : \textcolor{red}{$n$ rows}
                      \textcolor{red}{$q$ columns}};

\end{tikzpicture}

\begin{tikzpicture}[>=latex]
% unit
% defintion of matrices
\matrix (A) [matrix of math nodes,%
             nodes = {node style ge},%
             left delimiter  = (,%
             right delimiter = )] at (0,0)
{%
  a_{11} &\ldots & a_{1k} & \ldots & a_{1p}  \\
    \vdots & \ddots & \vdots & \vdots & \vdots \\
  |[node style sp]| a_{i1} & \ldots%
         & |[node style sp]| a_{ik}%
                  & \ldots%
                           & |[node style sp]| a_{ip} \\
  \vdots & \vdots& \vdots & \ddots & \vdots  \\
  a_{n1}& \ldots & a_{nk} & \ldots & a_{np}  \\
};
\node [draw,below] at (A.south)
      { $A$ : \textcolor{red}{$n$ rows} $p$ columns};
\matrix (B) [matrix of math nodes,%
             nodes = {node style ge},%
             left delimiter  = (,%
             right delimiter =)] at (7*\myunit,7*\myunit)
{%
  b_{11} &  \ldots& |[node style sp]| b_{1j}%
                  & \ldots & b_{1q}  \\
  \vdots& \ddots & \vdots & \vdots & \vdots \\
  b_{k1} &  \ldots& |[node style sp]| b_{kj}%
                  & \ldots & b_{kq}  \\
  \vdots& \vdots & \vdots & \ddots & \vdots \\
  b_{p1} &  \ldots& |[node style sp]| b_{pj}%
                  & \ldots & b_{pq}  \\
};
\node [draw,above] at (B.north)
      { $B$ : $p$ rows \textcolor{red}{$q$ columns}};
% matrice resultat
\matrix (C) [matrix of math nodes,%
             nodes = {node style ge},%
             left delimiter  = (,%
             right delimiter = )] at (7*\myunit,0)
{%
  c_{11} & \ldots& c_{1j} & \ldots & c_{1q} \\
  \vdots& \ddots & \vdots & \vdots & \vdots \\
    c_{i1}& \ldots & |[node style sp,red]| c_{ij}%
                  & \ldots & c_{iq} \\
  \vdots& \vdots & \vdots & \ddots & \vdots \\
  c_{n1}& \ldots & c_{nk} & \ldots & c_{nq} \\
};
\node [draw,below] at (C.south) 
    {$ C=A\times B$ : \textcolor{red}{$n$ rows}
                      \textcolor{red}{$q$ columns}};
% arrows
\draw[blue] (A-3-1.north) -- (C-3-3.north);
\draw[blue] (A-3-1.south) -- (C-3-3.south);
\draw[blue] (B-1-3.west)  -- (C-3-3.west);
\draw[blue] (B-1-3.east)  -- (C-3-3.east);
\draw[<->,red](A-3-1) to[in=180,out=90] 
    node[arrow style mul] (x) {$a_{i1}\times b_{1j}$} (B-1-3);
\draw[<->,red](A-3-3) to[in=180,out=90] 
    node[arrow style mul] (y) {$a_{ik}\times b_{kj}$}(B-3-3);
\draw[<->,red](A-3-5) to[in=180,out=90] 
    node[arrow style mul] (z) {$a_{ip}\times b_{pj}$}(B-5-3);
\draw[red,->] (x) to node[arrow style plus] {$+\raisebox{.5ex}{\ldots}+$} (y)
    to node[arrow style plus] {$+\raisebox{.5ex}{\ldots}+$} (z);
                  %
                  % to (C-3-3.north west);
\draw[->,red,decorate,decoration=zigzag] (z) -- (C-3-3.north west);
\end{tikzpicture}
\end{document}


pdf
PDF - 41 Ko

Posté par
Rintaro
re : Code latex produit matriciel 02-03-23 à 17:38

Je passe pour un sacré charlatan à côté de vos réponses avec mon site qui fait tout à ma place j'apprécie vos réponses verdurin, matheux14 et hekla (même si je ne suis pas l'auteur du post). Le dernier package a l'air vraiment bien.

Bonne journée.



Vous devez être membre accéder à ce service...

Pas encore inscrit ?

1 compte par personne, multi-compte interdit !

Ou identifiez-vous :


Rester sur la page

Désolé, votre version d'Internet Explorer est plus que périmée ! Merci de le mettre à jour ou de télécharger Firefox ou Google Chrome pour utiliser le site. Votre ordinateur vous remerciera !