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

MathGroup Archive 2009

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

Search the Archive

Re: Piecewise vs. /; ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg103915] Re: Piecewise vs. /; ?
  • From: David Bailey <dave at removedbailey.co.uk>
  • Date: Mon, 12 Oct 2009 06:38:15 -0400 (EDT)
  • References: <hashpc$qu8$1@smc.vnet.net>

Erik Max Francis wrote:
> I'm defining a piecewise function:
> 
> mmin = 0.08;
> mmax = 100;
> 
> \[Xi][m_] := Piecewise[
>     {{0.035 m^-1.3, 0.08 <= m <= 0.50},
>      {0.019 m^-2.2, 0.50 < m <= 1.00},
>      {0.019 m^-2.7, 1.00 < m <= 100}}]; (* stars per pc^3 *)
> 
> This works fine for plotting (which I won't show) and integrating:
> 
> In[5]:= Integrate[\[Xi][m], {m, mmin, mmax}]
> 
> Out[5]= 0.136978
> 
> If I try to define \[Xi][m] with /;, it doesn't work.  This version:
> 
> \[Xi][m_ /; 0.08 <= m <= 0.50] = 0.035 m^-1.3 ;
> \[Xi][m_ /; 0.50 < m <= 1.00] = 0.019 m^-2.2;
> \[Xi][m_ /; 1.00 < m <= 100] = 0.019 m^-2.7;
> (* stars per pc^3 *)
> 
> plots correctly but integrate refuses to do anything:
> 
> In[26]:= Integrate[\[Xi]2[m], {m, mmin, mmax}]
> 
> Out[26]= \!\(
> \*SubsuperscriptBox[\(\[Integral]\), \(0.08`\), \(100\)]\(\[Xi]2[
>     m] \[DifferentialD]m\)\)
> 
> This version (putting the /; in a different place):
> 
> \[Xi]3[m_] = 0.035 m^-1.3  /; 0.08 <= m <= 0.50;
> \[Xi]3[m_] = 0.019 m^-2.2 /; 0.50 < m <= 1.00;
> \[Xi]3[m_] = 0.019 m^-2.7 /; 1.00 < m <= 100;
> (* stars per pc^3 *)
> 
> neither plots properly (the plot is blank) nor integrates properly:
> 
> In[27]:= Integrate[\[Xi]3[m], {m, mmin, mmax}]
> 
> Out[27]= \!\(
> \*SubsuperscriptBox[\(\[Integral]\), \(0.08`\), \(100\)]\(\((
> \*FractionBox[\(0.035`\),
> SuperscriptBox[\(m\), \(1.3`\)]] /;
>      0.08` <= m <= 0.5`)\) \[DifferentialD]m\)\)
> 
> I was under the impression that these were equivalent; what am I missing?
> 
Integrate operates on Mathematical expressions - which Piecewise is 
considered to be - not on arbitrary pieces of code, which would be an 
impossibly demanding and somewhat ill-defined task.

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: Why init.m is not being loaded from Autload folder? [Mathematica 7]
  • Next by Date: Re: Piecewise vs. /; ?
  • Previous by thread: Piecewise vs. /; ?
  • Next by thread: Re: Piecewise vs. /; ?