Defining a function using common notation for absolute value (not Abs[x])

Discussion in 'Mathematica' started by Gianni, Sep 28, 2010.

  1. Gianni

    Gianni Guest

    Please refer to:

    http://www.accardi.com/tutor/AbsoluteValueNotationSnapShot.bmp

    Thanks in advance for any help here.


    In ASCII:

    The given function to work with: f(x) = (3^-|x|)

    Define it in Mathematica:

    f[x_]:=3^-Abs[x]

    f[x_]:=3^-|x|

    Syntax::tsntxi: "|x|" is incomplete; more input is needed.

    Syntax::sntxi: Incomplete expression; more input is needed.

    I am trying to display the absolute value exponent in the second
    function definition above in the way students will see it in a
    standard math text (with the vertical bars, not Abs, like in the first
    text line). The first definition above is without error (exponent
    shown as -Abs[x]). The second is what I am trying to define without
    error. I am trying to find the button (hopefully on the classroom
    assistant palette) that will produce the desired results. The button
    in the Typesetting section of the Classroom Assistant won't be
    implemented as an error free function definition as you see in the
    error messages.

    --------------------------------------------
     
    Gianni, Sep 28, 2010
    #1
    1. Advertisements

  2. At least in StandardForm Mathematica needs opening an closing operators. I did
    the following to make Abs[x] to be displayed as

    \[LeftBracketingBar]x\[RightBracketingBar]

    BracketingBar::usage="\[LeftBracketingBar]x\[RightBracketingBar] is
    Abs[x] in StandardForm."

    then I did:

    MakeExpression[RowBox[{"\[LeftBracketingBar]",x_,"\[RightBracketingBar]"}],
    StandardForm]:=MakeExpression[RowBox[{"Abs[",x,"]"}],StandardForm]

    MakeBoxes[Abs[x_],StandardForm]:=
    RowBox[{"\[LeftBracketingBar]",MakeBoxes[x],"\[RightBracketingBar]"}]

    I put these settings into my private initialations file, the last two
    into the Begin["`Private`"] part.

    Now you can enter Abs[x] and in the Output it shows as |x|.
    And you can enter Abs[x] as

    ESC l| ESC x ESC r| ESC

    If you want to Abs[x] as |x| in the Input Cell use Cell/Convert to
    StandardForm or the shortcut
     
    Peter Breitfeld, Sep 29, 2010
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.