5
$\begingroup$

As an easy exercise, I would like to define a function

$$f(x)=\pm x$$

and be able to ListPlot the function for some discrete values.

Here is what I tried

F[x_] := PlusMinus[x];
Table[F[x], {x, 1, 4}]

This gives me output

{\[PlusMinus]1, \[PlusMinus]2, \[PlusMinus]3, \[PlusMinus]4}

This is exactly what I want. But now I want to listplot it using

ListPlot[Table[F[x], {x, 1, 4}]]

But this does not give me output.

So, I guess my question is how to convert the output of PlusMinus[2] which is $\pm2$ to an array $\{-2,2\}$ so that I can do other operations on it.

$\endgroup$
2
  • 7
    $\begingroup$ PlusMinus has no built-in meaning apart from the typesetting. Do you want Around instead? $\endgroup$
    – Jason B.
    May 24 at 19:43
  • 4
    $\begingroup$ Why don't you just define F as F[x_] := {x, -x} ? $\endgroup$
    – lericr
    May 24 at 19:52

1 Answer 1

9
$\begingroup$

Per the documentation, you could define the function for PlusMinus:

PlusMinus[a_] := {-a, a}
\[PlusMinus]2
(* {-2,2} *)
ListPlot[Table[\[PlusMinus]i, {i, 4}]]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.