
Re: Mystifying Scoping of Piecewise Variable?
Posted:
Feb 3, 2011 5:29 AM


You want:
myFunc = Function[{x}, Piecewise[{{x^2, x < 0}, {x, x >= 0}}]];
Begin forwarded message:
From: Frank Iannarilli <frankeye@cox.net> Date: February 02, 2011 3:08:08 AM Subject: Mystifying Scoping of Piecewise Variable?
Perhaps I'm tired, but this is weird:
Clear[myFunc]
myFunc[y_] = Piecewise[{{x^2, x < 0}, {x, x >= 0}}] (Same behavior below for either Set(=) or SetDelayed(:=) )
Plot[myFunc[y], {y, 10, 10}] (returns empty plot)
Plot[myFunc[x], {x, 10, 10}] (returns "expected" piecewise function plot)
What is the scoping of the Piecewise variable, in this case "x"?
How can one write a Module that creates and returns a Piecewise function? The scope of its argument is unclear to me.
Thanks

