Thursday, March 31, 2011

[Latex] Simultaneous Equations in Latex

Writing Simultaneous Equations in Latex using cases command, by default, it deems the whole group of equations as one equation and only gives one number for the whole set. 

If we want to add numbering to each of the equations inside the group, it's a little difficult. 

One solution I found on the web is as follows:

1) define a new command:

\newenvironment{ncases}[4]{%

\parbox{0.5\textwidth}{%

\begin{equation*}

#1=

\begin{cases}

#2

\end{cases}

\end{equation*}}

\hfill

\parbox{1cm}{%

\begin{eqnarray}

{}\label{#3}\\

{}\label{#4}

\end{eqnarray}}}


Note: this command only supports two equations, if needed one can extend it easily to the number you want. 


2) Use that command instead of the case command:


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\newenvironment{ncases}[4]{%

\parbox{0.5\textwidth}{%

\begin{equation*}

#1=

\begin{cases}

#2

\end{cases}

\end{equation*}}

\hfill

\parbox{1cm}{%

\begin{eqnarray}

{}\label{#3}\\

{}\label{#4}

\end{eqnarray}}}


\begin{document}

\begin{spacing}{1.1}


\begin{ncases}

{|x|}{x, &\text{if $x\ge 0$}\\

-x,&\text{if $x\le 0$}}{pos}{neg}

\end{ncases}


For if $x\ge 0$, then by Equation~\eqref{pos}, we have $|x|=x\ge0$ and 

if $x\le0$, then by Equation~\eqref{neg}, we have $|x|=-x\ge0$. 


\end{spacing}

\end{document}

Posted via email from Troy's posterous

No comments:

Post a Comment

Google+