Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Mystifying Scoping of Piecewise Variable?
Replies: 6   Last Post: Feb 3, 2011 5:33 AM

 Messages: [ Previous | Next ]
 Bob Hanlon Posts: 2,604 Registered: 1/29/05
Re: Mystifying Scoping of Piecewise Variable?
Posted: Feb 3, 2011 5:32 AM

Your function definition uses different variables on LHS and RHS. Use

myFunc[x_] = Piecewise[{{x^2, x < 0}, {x, x >= 0}}];

and both plots will work.

Bob Hanlon

---- Frank Iannarilli <frankeye@cox.net> wrote:

=============
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

Date Subject Author
2/2/11 Frank Iannarilli
2/3/11 Tomas Garza Hernandez
2/3/11 Albert Retey
2/3/11 Charles Gillingham
2/3/11 DrMajorBob
2/3/11 Bob Hanlon
2/3/11 DrMajorBob