MHB How to get a function that changes depending on x

  • Thread starter Thread starter tmt1
  • Start date Start date
  • Tags Tags
    Function
AI Thread Summary
To create a piecewise function in LaTeX, the discussion outlines a method using the "Begin/End" button in the LaTeX Live Preview feature. Users can select "Piecewise Function" from a dropdown menu, input the function name (e.g., f(x)), and define each piece along with its domain. The example provided demonstrates how to format the function: |2 - x| = { 2 - x if x ≤ 2, x - 2 if x > 2. This code can be generated in the live preview and copied into the post. The discussion emphasizes the utility of the Quick LaTeX element for finding necessary symbols. Overall, the guidance helps users effectively write conditional functions in LaTeX.
tmt1
Messages
230
Reaction score
0
Hi,

I want to write a function whereby if x > 2 the function is one thing, and if x <= 2 it is something else.

How could I write this with latex?
 
Physics news on Phys.org
When you are composing your post, look below the posting area to the $\LaTeX$ Live Preview element. on the bottom row, you will see a button labeled "Begin/End" which will allow you to easily compose things using the begin/end environment, among these are piecewise functions.

So, click the "Begin/End" button, and then from the drop-down menu, choose "Piecewise Function" and then in the first input element, give the function's name, such as $f(x)$, and then in the other input element, define each function piece, and its domain, separated by a comma.

Once you have this defined, then click "Submission Options" and choose the tags with which you wish for the code to be wrapped, and whether you want this to be inserted in the live preview, or for it to replace what is there, then if you are finished, click "Submit/Close" and the code will be generated in the live preview, and it you like what you see, you can copy this code to your post message, at the current cursor location there using the "Copy to Post" button.

If you are not certain what $\LaTeX$ codes to use for your definitions, use the Quick $\LaTeX$ element to the right, from which you can choose the symbols you will need.
 
tmt said:
Hi,

I want to write a function whereby if x > 2 the function is one thing, and if x <= 2 it is something else.

How could I write this with latex?

How about this?

$\displaystyle \begin{align*} \left| 2 - x \right| = \begin{cases} 2 - x \textrm{ if } x \leq 2 \\ x- 2 \textrm{ if } x > 2 \end{cases} \end{align*}$

If you hover over the LaTeX you will see the code.
 
Prove It said:
How about this?

$\displaystyle \begin{align*} \left| 2 - x \right| = \begin{cases} 2 - x \textrm{ if } x \leq 2 \\ x- 2 \textrm{ if } x > 2 \end{cases} \end{align*}$

If you hover over the LaTeX you will see the code.

Thanks that is what I was looking for
 

Similar threads

Replies
8
Views
3K
Replies
13
Views
2K
Replies
3
Views
2K
Replies
4
Views
2K
Back
Top