How can I write a piecewise function in LaTeX?

TheBigBadBen
Messages
79
Reaction score
0
I was trying to type a piecewise function, and then this happened:

$$
f(x)=\left{ \begin{array}{ccc}
1 & x \in \mathbb{Q} \\
0 & x \notin \mathbb{Q}
\end{array} \right
$$

What's going on, and how do I fix it?
 
Hi TheBigBadBen, :)

There are two small things to fix and it works just fine. The first is when you want to add brackets {} using Mathjax you need to add another slash before it. So it should read "\left \{". The other thing is at the end of "\right" you need to add a period. If you do those two things this is what renders.

$$
f(x)=\left\{ \begin{array}{ll}
1 & x \in \mathbb{Q} \\
0 & x \notin \mathbb{Q}
\end{array} \right.$$
 
Another approach:

Try the code:

Code:
f(x)=\begin{cases}1 & x\in\mathbb{Q}\\ 0 & x\notin\mathbb{Q} \\ \end{cases}

to get:

$$f(x)=\begin{cases}1 & x\in\mathbb{Q}\\ 0 & x\notin\mathbb{Q} \\ \end{cases}$$
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K