Re: Piecewise inside a Module or Block, I don't understand this
- To: mathgroup at smc.vnet.net
- Subject: [mg83300] Re: Piecewise inside a Module or Block, I don't understand this
- From: "W. Craig Carter" <ccarter at mit.edu>
- Date: Sat, 17 Nov 2007 05:17:25 -0500 (EST)
- References: <fhjs9v$4vg$1@smc.vnet.net> <473DA496.5050509@gmail.com>
>> 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*) > > All this is just about a syntax error you made. > > First, note that, as posted, none of the above examples works: they both Cher Jean-Marc, I don't get an error when I cut and paste this expression. Math6.01 And, the posted work-around works just fine: 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] Note, that this seems to be peculiar to Piecewise: e.g, a[c_, d_] := Module[{e, f}, e = d^2; f = c^2; Return[MyUnAssignedFunction[{e, 0 < x < 1/2}, {f, 1/2 < x <= 1}]]]; ` a[1,2] works as I hoped. PS: My goal here was to write a function that made a calculation of the bounds, and then returned a piecewise function of x that had the bounds as explicitly calculated.