Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Piecewise inside a Module or Block, I don't understand this behavior.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg83260] Piecewise inside a Module or Block, I don't understand this behavior.
  • From: "W. Craig Carter" <ccarter at mit.edu>
  • Date: Fri, 16 Nov 2007 05:31:22 -0500 (EST)

Hello,

I have a Piecewise function calculated in a module:
Here is a simplifed example of something which has a
behavior that puzzles me.

a[c_, d_] :=
  Module[{e, f}, e = d^2; f = c^2;
   Return[Piecewise[{e, 0 < x < 1/2}, {f, 1/2 < x <= 1}]]];
a[1,2] (*doen't return what I had anticipated*)

(*However this does*)
a[c_, d_] :=
Module[{e, f}, e = d^2; f = c^2;
Return[Piecewise[{d^2, 0 < x < 1/2}, {c^2, 1/2 < x <= 1}]]];
a[1,2]

(*The same goes for Block, and putting an explicit Evaluate
inside the local function*)

(*This behavior seems to be unique to Piecewise*)
a[c_, d_] :=
Module[{e, f}, e = d^2; f = c^2;
Return[MyFunction[{e, 0 < x < 1/2}, {f, 1/2 < x <= 1}]]];
a[1,2]

I can't find anything about Piecewise, or in Module and
Block documentation that gives me a hint.

Anyone know what is going on?

Thanks, Craig

PS: I have a work-around:

aAlt[c_, d_] :=
Module[{e, f}, e = d^2; f = c^2;
{{e, 0 < x < 1/2}, {f, 1/2 < x <= 1}}];
Piecewise@aAlt[1,2]

but, I am still curious....


  • Prev by Date: Re: Re: Can't abort a loop with Print inside (V6)
  • Next by Date: Re: Default value for Dynamic InputField
  • Previous by thread: Re: Does ColorFunction-> have different meanings to Plot3D and
  • Next by thread: Re: Piecewise inside a Module or Block, I don't understand this behavior.