Math & ScienceSystem of equations

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
solunac
Posts: 5
Joined: Thu Dec 17, 2009 8:58 pm

System of equations

Post by solunac »

Hi!

I am stuck with system of linear equations. I need to put them aligned so that it looks like this:
Image

I wrote a code (but wrong) so you can work with it.

Code: Select all

\begin{align*}
x_0           &+\frac{7}{22}x_3 &+\frac{5}{22}x_4      &= \frac{21}{2}\\
    &x_1      &+\frac{3}{22}x_3 &-\frac{1}{22}x_4      &= \frac{7}{2}\\
         &x_2 &+\frac{1}{22}x_3 &+\frac{7}{22}x_4      &= \frac{7}{2}\\
              &\frac{3}{2}x_3   &+\frac{5}{2}x_4 &+x_5 &= \frac{55}{2}.
\end{align*}
Thanks in advance.

Recommended reading 2024:

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

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

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

System of equations

Post by frabjous »

Align and similar environments will always put something right aligned next to something left aligned, as in an equation, but you want something more complicated than that. All parts are left or center aligned. I guess I might try an array. E.g.:

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation*}
\begin{array}{cccllllc}
x_0 &    &    &+\frac{7}{22}x_3 &+\frac{5}{22}x_4 &     &=&\frac{21}{2}\\[1ex]
    &x_1 &    &+\frac{3}{22}x_3 &-\frac{1}{22}x_4 &     &=&\frac{7}{2}\\[1ex]
    &    &x_2 &+\frac{1}{22}x_3 &+\frac{7}{22}x_4 &     &=&\frac{7}{2}\\[1ex]
    &    &    &+\frac{3}{2}x_3   &+\frac{5}{2}x_4  &+x_5 &=&\frac{55}{2}.
\end{array}
\end{equation*}
\end{document}
solunac
Posts: 5
Joined: Thu Dec 17, 2009 8:58 pm

Re: System of equations

Post by solunac »

Thanks, one more time! :D
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

System of equations

Post by localghost »

Just for the record. The alignment done with alignat environment.

Code: Select all

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}

\allowdisplaybreaks

\begin{document}
  \begin{alignat*}{6}
    x_0 &    &&    &&+\tfrac{7}{22}x_3      &&+\tfrac{5}{22}x_4 &&     &&= \tfrac{21}{2} \\
        &x_1 &&    &&+\tfrac{3}{22}x_3      &&-\tfrac{1}{22}x_4 &&     &&= \tfrac{7}{2} \\
        &    &&x_2 &&+\tfrac{1}{22}x_3      &&+\tfrac{7}{22}x_4 &&     &&= \tfrac{7}{2} \\
        &    &&    &&\quad\,\tfrac{3}{2}x_3 &&+\tfrac{5}{2}x_4  &&+x_5 &&= \tfrac{55}{2}
  \end{alignat*}
\end{document}
Not exactly what you want, but wouldn't cause trouble if it comes to a page break. Horizontal spaces can be customized.


Best regards and welcome to the board
Thorsten
azoun
Posts: 3
Joined: Wed Dec 02, 2009 1:47 am

System of equations

Post by azoun »

here it is my solution

Code: Select all

\begin{equation*}
\begin{array}{cccllllc}
x_0 &    &    &+\frac{7}{22}x_3 &+\frac{5}{22}x_4 &     &=&\frac{21}{2}\\[1ex]
    &x_1 &    &+\frac{3}{22}x_3 &-\frac{1}{22}x_4 &     &=&\frac{7}{2}\\[1ex]
    &    &x_2 &+\frac{1}{22}x_3 &+\frac{7}{22}x_4 &     &=&\frac{7}{2}\\[1ex]
    &    &    &+\frac{3}{2}x_3   &+\hfill\frac{5}{2}x_4  &+x_5 &=&\frac{55}{2} %<---HERE
\end{array}
\end{equation*}
I prefer so

Code: Select all

\begin{equation*}
\begin{array}{cccllllc}
x_0 &    &    &+\frac{7}{22}x_3 &+\frac{5}{22}x_4 &     &=&\frac{21}{2}\\[1ex]
    &x_1 &    &+\frac{3}{22}x_3 &-\frac{1}{22}x_4 &     &=&\frac{7}{2}\\[1ex]
    &    &x_2 &+\frac{1}{22}x_3 &+\frac{7}{22}x_4 &     &=&\frac{7}{2}\\[1ex]
    &    &    &+\frac{3}{2}x_3   &+\hfill\frac{5}{2}x_4  &+x_5 &=&\frac{55}{2}%<---HERE
\end{array}
\end{equation*}
tonyjnel
Posts: 11
Joined: Thu May 12, 2011 3:51 pm

System of equations

Post by tonyjnel »

This is almost what I am looking for but there is too much space between the elements of the array. I want mine to read just like an equation (like the rest of my equations that aren't arrays) so that my paper is consistent. I tried this:

Code: Select all

\begin{align*}
5x_1&+3x_2&+x_3&=0\\
x_1&+{}&-4x_3&=0\\
{}&-9x_2&+2x_3&=0\end{align*}
and the first two terms look great but then there is a huge gap between the next ones.

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

System of equations

Post by Stefan Kottwitz »

Hi Tony,

you could use the alignat* environment. It allows alignment at several places. A mandatory argument specifies the number of columns. For example:

Code: Select all

\begin{alignat*}{2}
5x_1 &+ 3x_2 &&+ x_3  &= 0\\
 x_1 &+      &&- 4x_3 &= 0\\
     &- 9x_2 &&+ 2x_3 &= 0
\end{alignat*}
Stefan
LaTeX.org admin
tonyjnel
Posts: 11
Joined: Thu May 12, 2011 3:51 pm

System of equations

Post by tonyjnel »

Thanks Stefan! That is exactly what I wanted. I think there were some typos in your code though.. LaTeX didn't give me errors when I changed it to

Code: Select all

\begin{alignat*}{4}
5x_1 &+ 3x_2 &+ x_3  &= 0\\
x_1 &+      &- 4x_3 &= 0\\
     &- 9x_2 &+ 2x_3 &= 0
\end{alignat*}
-Tony
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

System of equations

Post by Juanjo »

In my opinion, your code generates a system of equations with some flaws: there is a superfluous + sign in the second row, signs are not vertically aligned, the spacing around signs is not correct...
Please, try this:

Code: Select all

\begin{alignat*}{3}
  5x_1 &+{}& 3x_2 &+{}&  x_3 &= 0 \\
   x_1 &   &      &-{}& 4x_3 &= 0 \\
       &-{}& 9x_2 &+{}& 2x_3 &= 0
\end{alignat*}
The mandatory argument of alignat is the number of «columns» in the aligned formulas (in this case, one column for each variable x_i; the third and last column also contains the independent terms). Two consecutive columns are separated by an ampersand (&). In each column, the alignment point is also marked by an ampersand. So, if there are n columns, there should be 2n-1 ampersands per row. In every row, the first ampersand marks the aligment point for the first column; the second ampersand marks the end of the first column; the third ampersand marks the alignment point for the second column; and so on.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
unbonpetit

System of equations

Post by unbonpetit »

Can I suggest the use of the "systeme" package:

Code: Select all

\documentclass{minimal}
\usepackage{systeme}
\begin{document}
My system:
\systeme{x_0+\frac{7}{22}x_3+\frac{5}{22}x_4=\frac{21}{2},
x_1+\frac{3}{22}x_3-\frac{1}{22}x_4=\frac{7}{2},
x_2+\frac{1}{22}x_3+\frac{7}{22}x_4=\frac{7}{2},
\frac{3}{2}x_3+\frac{5}{2}x_4+x_5=\frac{55}{2}}

Another one:
\systeme{5x_1+3x_2+x_3=0,
x_1-4x_3=0,
-9x_2+2x_3=0}
\end{document}
Post Reply