0

How can I make a function that returns $g(x)$ if $x$ belongs to $(0,10)$ and returns $h(x)$ if not? Like this :$$ f(x)=\begin{cases} \ g(x) & 0<x<10,\\ h(x) & \text{otherwise}. \end{cases} $$ I think it's like an if-else block in a programming language

subrosar
  • 5,086
sankiago
  • 55
  • 6
  • 4
    What do you mean by "make"? It's more or less what you have written (except it's $0<x<10$). You don't need anything else to define such a piecewise function. See https://en.wikipedia.org/wiki/Piecewise#Notation_and_interpretation – Jean-Claude Arbaut Oct 17 '21 at 23:05
  • For example i have this: $\begin{align} f(x)&= \begin{cases} g(x)\phantom{x}\forall\phantom{x} x\text{ even}\ h(x)\phantom{x}\forall\phantom{x} x\text{ odd} \end{cases}\ \ f(x)&=\frac{1}{2}\left(1+(-1)^{x}\right)\cdot g(x)+\frac{1}{2}\left(1-(-1)^{x}\right)\cdot h(x) \end{align}$ – sankiago Oct 17 '21 at 23:07
  • that's what I mean by "make" – sankiago Oct 17 '21 at 23:07
  • 2
    Not a very good idea. To begin with, how do you define $(-1)^x$ when $x$ is not an integer? Often, it's absolutely not practical to resort to such tricks to write a piecewise function as a single expression, as you are only left with something more complicated. Sometimes there is a clever way (see for instance this answer and the comments). Or you may use Iverson brackets, which are just a notation trick to replace the usual piecewise definition. – Jean-Claude Arbaut Oct 17 '21 at 23:13

0 Answers0