I have created this code:
xn = {4, -4, 4, -4}
f[x_] = Piecewise[{{Sqrt[x], x >= 0}, {Sqrt[-x], x < 0}}]
f[xn]
With this code I would expect as a result:
{2,2,2,2}
But that's not what I get.
Question 1 - Why don't I get the desired result?
Question 2 - How to get the desired result?
f/@xnorSetAttributes[f, Listable]... – ciao Jul 12 '16 at 21:09Sqrt[Abs[x]]? – J. M.'s missing motivation Jul 12 '16 at 21:11/@and press F1, so that you can answer your own question. – J. M.'s missing motivation Jul 12 '16 at 21:11Set(=) does not scope the symbolxwhich may lead to trouble – Sascha Jul 12 '16 at 21:12