1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

A Switch function?

  1. Sep 26, 2014 #1
    Hi i was wondering if there is such a function/operator/something that restricts a function within an interval. I know that doesn't make a lot of sense but ill show you what i mean;

    Say i want to define f(x) = x for 0<x<a and f(x) = sqrt(x) for x>a. Now i know this is easily represented as a piecewise function, but i do not want this to be a pieceswise function.

    So instead I define g(x) = &{x} + %{sqrt(x)} where the &{} is some type of operator that is 1 when 0<x<a and 0 elsewhere and the %{} is a similar operator that is 1 when x>a and 0 elsewhere. What this 'operator' (probably not the right term) is effectively doing is switching the function for a given interval... i apologise for the abstractness.
  2. jcsd
  3. Sep 26, 2014 #2


    User Avatar
    Science Advisor

  4. Sep 27, 2014 #3
    HEY! I know about this! I hope you're still watching this thread. I frequently need "mathematical cheat codes" which implement weird functions in terms of what you normally put into a calculator.

    Consulting my recipe book, there's a few ways to do this. For clarity, I'll name the function which is 1 until x, then turns to 0, f(x); and the function which is 0 until x, then turns to 1, g(x).

    You can derive these both from the sgn(x) function, which you can implement with f(x) / |f(x)|. Using the rules for translating and stretching functions, you end up with:

    f(x) = (x-A)/(2abs(x-A)+(1/2)

    g(x) = (A-x)/(2abs(A-x)+(1/2)

    If you aren't allowed to use the absolute value function, you can implement that with sqrt(f(x)^2). Due to how only the principal value is taken.

    Note, the above functions are indeterminate at x = 0. You can use the Kronecker delta function to get a function which is 0 at all points except A, where it is some number you specify. This is 0^abs(x), assuming your use-case assumes indeterminate values to be zero, and not, say, an error.

    If indeterminate values are a problem, you can use the particularly evil identity sgn(x) = tanh(1000000x).

    So, the most rigorous function I can give is f(x) = tanh(1000000(x-A))/2+1/2 and g(x) = tanh(1000000(A-x))/2+1/2

    Your final function R(x) will just be xf(x)+sqrt(x)g(x).
  5. Sep 28, 2014 #4
  6. Oct 7, 2014 #5
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook