How to get a function that changes depending on x

  • Context: MHB 
  • Thread starter Thread starter tmt1
  • Start date Start date
  • Tags Tags
    Function
Click For Summary

Discussion Overview

The discussion revolves around how to define a piecewise function in LaTeX, specifically one that changes its expression based on the value of the variable x, with conditions for x being greater than or less than or equal to 2.

Discussion Character

  • Technical explanation, Mathematical reasoning

Main Points Raised

  • One participant inquires about writing a function that behaves differently based on the value of x, specifically for the conditions x > 2 and x <= 2.
  • Another participant provides guidance on using the LaTeX Live Preview feature to create piecewise functions, detailing the steps to define the function and its domain.
  • A participant suggests a specific LaTeX representation of the piecewise function, using the absolute value to express the function's behavior based on the conditions provided.
  • A later reply reiterates the suggested LaTeX code for the piecewise function, confirming it meets the initial request.

Areas of Agreement / Disagreement

Participants generally agree on the approach to writing the piecewise function in LaTeX, with no significant disagreement noted in the responses.

Contextual Notes

The discussion is limited to the formatting of the piecewise function in LaTeX and does not delve into the mathematical implications or applications of the function itself.

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
5
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 16 ·
Replies
16
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K