Math & ScienceGauss-Jordan Elimination

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
Math12345
Posts: 8
Joined: Sun Aug 07, 2011 7:20 am

Gauss-Jordan Elimination

Post by Math12345 »

Dear friends,

Writing a compendium in basic Linear Algebra with LaTeX I encountered a serious problem trying to code Gauss-Jordan elimination. The best thing I could come up with follows below, however I am very miss-pleased with this. I would like to get something more compact with smaller matrices. My problem was I don't know how to implement those rings indicating row-operations. I appreciate all comments and suggestions on how to improve the result.

All the best
Paul

Code: Select all

$$
\begin{xy}
*!C\xybox{\xymatrix{
1 & 1 & 1  &^{}  \ar@{-}[dd]&3\\ 2 & 4 & 6&&4 \\ 20 & 26 & 28 &&4
}\POS="matrix"
,"matrix"!L*\frm{(},"matrix"!R*\frm{)},"1,5"+/r.2cm/,\xymatrix @C-2pc{{}&\circled{-2} \ar[dl]&\circled{-20} \ar[ddll]\\
{}&&\\
&&&}}
\end{xy}
\hskip 10 pt \sim\hskip 10 pt
 \begin{xy}
*!C\xybox{\xymatrix{
1 & 1 & 1  &^{}  \ar@{-}[dd]&3\\ 0 & 2 & 4&&-2 \\ 0 & 6 & 8 &&-56
}\POS="matrix"
,"matrix"!L*\frm{(},"matrix"!R*\frm{)},"1,5"+/r.8cm/,\xymatrix {{}\\
\times \frac{1}{2}\\
{}}}
\end{xy}\hskip 10 pt \sim
$$


$$
\begin{xy}
*!C\xybox{\xymatrix{
1 & 1 & 1  &^{}  \ar@{-}[dd]&3\\ 0 & 1& 2&&-1 \\ 0 & 6 & 8 &&-56
}\POS="matrix"
,"matrix"!L*\frm{(},"matrix"!R*\frm{)},"1,5"+/r.5cm/,\xymatrix @C-2pc{{}&&&\\&\circled{-1} \ar[ul]&\circled{-6} \ar[dll]\\
{}&&
}}
\end{xy}
\hskip 10 pt \sim\hskip 10 pt
\begin{xy}
*!C\xybox{\xymatrix{
1 & 0 & -1  &^{}  \ar@{-}[dd]&4\\ 0 & 1& 2&&-1 \\ 0 & 0 & -4 &&-50
}\POS="matrix"
,"matrix"!L*\frm{(},"matrix"!R*\frm{)},"1,5"+/r1.0cm/,\xymatrix {{}\\
{}\\
\times -\frac{1}{4}
}}
\end{xy}
\hskip 10 pt \sim
$$

$$
\begin{xy}
*!C\xybox{\xymatrix{
1 & 0 & -1  &^{}  \ar@{-}[dd]&4\\ 0 & 1& 2&&-1 \\ 0 & 0 & 1 &&\frac{25}{2}
}\POS="matrix"
,"matrix"!L*\frm{(},"matrix"!R*\frm{)},"1,5"+/r.5cm/,\xymatrix @C-2pc{{}&&\\&&\\
&\circled{-2} \ar[ul]&\circled{1} \ar[uull]
}}
\end{xy}
\hskip 10 pt \sim\hskip 10 pt
\begin{xy}
*!C\xybox{\xymatrix{
1 & 0 & 0  &^{}  \ar@{-}[dd]&\frac{33}{2}\\ 0 & 1& 0&&-26 \\ 0 & 0 & 1 &&\frac{25}{2}
}\POS="matrix"
,"matrix"!L*\frm{(},"matrix"!R*\frm{)}}
\end{xy}
$$
Last edited by localghost on Tue Feb 14, 2012 7:04 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Gauss-Jordan Elimination

Post by localghost »

Since I can't supplement your code snippet to a complete minimal example, I can only refer you to the gauss package.


Thorsten
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Gauss-Jordan Elimination

Post by Stefan Kottwitz »

Hi Paul,

in my opinion xy is very hard to read. For such purposes I prefer TikZ, even if it's just for connecting matrix elements by arrows.

Have a look at this example:
matrices.png
matrices.png (12.82 KiB) Viewed 18350 times
Stefan
LaTeX.org admin
Math12345
Posts: 8
Joined: Sun Aug 07, 2011 7:20 am

Re: Gauss-Jordan Elimination

Post by Math12345 »

Dear friends,

Thanks for suggestions, however I didn't succeeded to create the appropriate code.
I supply the picture what I want to get, but just more elegant (not with artificially oversized matrix).
The numbers in rings show the current row-operation (local Swedish notation), and I want
to keep them this way. The only thing I need is too shrink the matrix to the standard size
as in any other latex-created text.
Yes, maybe TikZ could work, but I have now no clue how to do it. So, if you by chance know
how to proceed, please let me know….

All best,
Paul
Attachments
My attempt for Gauss-Jordan
My attempt for Gauss-Jordan
Gauss-Jordan.png (12.79 KiB) Viewed 18315 times
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Gauss-Jordan Elimination

Post by localghost »

What about just showing the code in form of a minimal example that produces this output?
Math12345
Posts: 8
Joined: Sun Aug 07, 2011 7:20 am

Gauss-Jordan Elimination

Post by Math12345 »

Yes, you are right. Here comes the minimal example:

Code: Select all

\documentclass[12pt,a4paper,reqno,openany,makeidx]{amsbook}
\usepackage[all]{xy}
\newcommand{\circled}[1]{\xybox{*+[Fo]{#1}}}

\begin{document}
$$
\begin{xy}
*!C\xybox{\xymatrix{
1 & 1 & 1  &^{}  \ar@{-}[dd]&3\\ 2 & 4 & 6&&4 \\ 20 & 26 & 28 &&4
}\POS="matrix"
,"matrix"!L*\frm{(},"matrix"!R*\frm{)},"1,5"+/r.2cm/,\xymatrix @C-2pc{{}&\circled{-2} \ar[dl]&\circled{-20} \ar[ddll]\\
{}&&\\
&&&}}
\end{xy}
\hskip 10 pt \sim\hskip 10 pt
 \begin{xy}
*!C\xybox{\xymatrix{
1 & 1 & 1  &^{}  \ar@{-}[dd]&3\\ 0 & 2 & 4&&-2 \\ 0 & 6 & 8 &&-56
}\POS="matrix"
,"matrix"!L*\frm{(},"matrix"!R*\frm{)},"1,5"+/r.8cm/,\xymatrix {{}\\
\times \frac{1}{2}\\
{}}}
\end{xy}\hskip 10 pt \sim
$$
\end{document}
I hope you can see what I mean.
My best regards
Paul
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Gauss-Jordan Elimination

Post by Stefan Kottwitz »

Hi Paul,

you could use @R and C@ for specifying a default row and column spacing, such as

Code: Select all

\begin{xy}
*!C\xybox{\xymatrix@R.5ex@C.6em{
1 & 1 & 1  &^{}  \ar@{-}[dd]&3\\ 0 & 2 & 4&&-2 \\ 0 & 6 & 8 &&-56
}\POS="matrix"
,"matrix"!L*\frm{(},"matrix"!R*\frm{)},"1,5"+/r.8cm/,\xymatrix {{}\\
\times \frac{1}{2}\\
{}}}
\end{xy}
xymatrix.png
xymatrix.png (2.72 KiB) Viewed 18291 times
Stefan
LaTeX.org admin
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Gauss-Jordan Elimination

Post by localghost »

Math12345 wrote:[…] Yes, maybe TikZ could work, but I have now no clue how to do it. So, if you by chance know
how to proceed, please let me know…. […]
The example below shows some modified code from my archives.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{tikz}
\usetikzlibrary{calc,matrix,positioning}

\begin{document}
  \begin{tikzpicture}[
    >=stealth,
    every left delimiter/.style={xshift=1em},
    every right delimiter/.style={xshift=-1em}
  ]
    \matrix (gauss) [
      matrix of math nodes,
      nodes={minimum width=2em},
      left delimiter=(,
      right delimiter=),
      row sep=0.5em,
    ]{
      1  & 1  & 1  & 3 \\
      2  & 4  & 6  & 4 \\
      20 & 26 & 28 & 4 \\
    };
    \draw (gauss-1-3.north east) -- (gauss-3-3.south east);
    \node[draw,circle,minimum size=2em,inner sep=0pt,node distance=1em,right=of gauss-1-4] (m1) {-2};
    \node[draw,circle,minimum size=2em,inner sep=0pt,node distance=0.5em,right=of m1] (m2) {-20};
    \draw[->] (m1) |- ($(gauss-2-4)+(1.5em,0)$) node[midway,right] {$+$};
    \draw[->] (m2) |- ($(gauss-3-4)+(1.5em,0)$) node[midway,right] {$+$};
  \end{tikzpicture}
\end{document}
For code modifications according to your demands please refer to the pgf/tikZ user guide.
Attachments
The rendered output of the given code.
The rendered output of the given code.
tikZ-Gauss-Jordan.png (13.96 KiB) Viewed 18287 times
Math12345
Posts: 8
Joined: Sun Aug 07, 2011 7:20 am

Re: Gauss-Jordan Elimination

Post by Math12345 »

Thank you VERY much. I appreciate really all help I got. Now I have everything I needed in order to sole our problem. It works just perfect.
Thanks, Paul
Post Reply