Math & ScienceBrackets for equality

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
generator
Posts: 9
Joined: Sat Apr 03, 2010 5:56 am

Brackets for equality

Post by generator »

I haven't found any documentation on brackets with equality.

I'm attempting to define a function (the Collatz conjecture - see http://en.wikipedia.org/wiki/Collatz_conjecture)

I set up the equality

f(n) = {n/2 if n is even
{3n+1 if n is odd

I'd like to combine the brackets, just like in the link above. Is this possible?

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

Brackets for equality

Post by frabjous »

You could use the cases environment of amsmath:

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
f(n) = 
\begin{cases}
n/2 &\text{if $n$ is even} \\
3n+1 &\text{if $n$ is odd} 
\end{cases}
\]
\end{document}
generator
Posts: 9
Joined: Sat Apr 03, 2010 5:56 am

Re: Brackets for equality

Post by generator »

Thanks for your help. That's exactly what I wanted. However, I'd also like to put this into an equation, numbered for clarity. How would I do this?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Brackets for equality

Post by localghost »

generator wrote:[…] However, I'd also like to put this into an equation, numbered for clarity. How would I do this?
What about using the equation environment? Perhaps some basic reading would be good for you.


Best regards and welcome to the board
Thorsten
generator
Posts: 9
Joined: Sat Apr 03, 2010 5:56 am

Re: Brackets for equality

Post by generator »

I've been trying to read up on this. However, I don't know how to use the equation environment in conjunction with another begin/end clause. My TeX editor keeps telling me there are like 8-10 errors when I try this. How would I get around this?
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Brackets for equality

Post by frabjous »

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
f(n) =
\begin{cases}
n/2 &\text{if $n$ is even} \\
3n+1 &\text{if $n$ is odd}
\end{cases}
\label{collatzfunction}
\end{equation}
As you can see in (\ref{collatzfunction}), blah blah blah.
\end{document}
Last edited by frabjous on Sat Apr 03, 2010 3:59 pm, edited 1 time in total.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Brackets for equality

Post by localghost »

I strongly recommend to do some basic reading [1]. If you are already struggling with these basic things, you will never put your work to paper.

[1] View topic: LaTeX Resources for Beginners
Post Reply