GNU Octave, MATLAB, Mathematica and Sage all include libraries of commonly used mathematical functions (as well as numerous not so commonly used mathematical functions). This page shows the syntax for invoking the absolute value function on each of these systems. The Mathematica section also includes an example showing how the system can be used to simplify logical expressions.
The absolute value function in Octave (and MATLAB) is abs().
These systems are case sensitive, so Abs()
and ABS()
are not correct.
If you give abs() a complex number, the
modulus will be computed. As you may know MATLAB stands for MatrixLaboratory,
so it's not surprising that abs(), like many other MATLAB functions,
is perfectly happy to be fed an array of inputs. See the session below.
octave:1> abs( -3 ) ans = 3 octave:2> ABS( -3 ) error: `ABS' undefined near line 2 column 1 octave:2> abs( 3 - 4i ) ans = 5 octave:3> abs( [ 2 -7 -3.4 8.2 -1.03 12+5i ] ) ans = 2.0000 7.0000 3.4000 8.2000 1.0300 13.0000
The absolute value function in Mathematica is Abs[].
Mathematica is case sensitve, so abs[]
won't work.
Note also that Mathematica uses square brackets, not parentheses
for function invocation, so Abs()
will also fail
to invoke the absolute value function. If you give Abs[]
a complex number, Mathematica will compute the number's modulus.
If you feed it a list of numbers, the corresponding list of
absolute values (or moduli) will be returned. See the following
examples. (Note that in a Mathematica notebook simply pressing
the
Enter
key does
not send the contents of the current cell to the
Mathematica kernel for evaluation. It merely starts a new line
in the current cell. To evaluate the cell you need to
press
Shift-
Enter.)
The following Mathematica snippet shows that Mathematica can be used to simplify logical expressions. In particular, Mathematica can determine that $2 < x < 6$ necessarily entails $|x-4|<2$. By contrast, the implication $2 < x < 6 => 0 < x < 4$ holds for some, but not all, values of $x$.
The absolute value function in Sage is abs(). It may be applied to real or complex numbers. Click any of the Evaluate buttons below to send the corresponding commands to a Sage Cell Server for evaluation. (Alternatively, press Shift- Enter with the cursor in the cell.) The input cells are editable, so feel free to experiment.