From: Erik Max Francis on 11 Oct 2009 08:07 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? -- Erik Max Francis && max(a)alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis If you're not beside me / I'll do your best / To carry on -- India Arie
From: David Bailey on 12 Oct 2009 06:38 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
From: Szabolcs Horvát on 12 Oct 2009 06:43 On 2009.10.11. 14:07, 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? > In short, /; is a programming construct that affects evaluation. Piecewise[] is used to represent a mathematical concept: piecewise functions. If you want to do mathematical operations like integration, then use Piecewise[]. Condition[] (/;) is a lot more general than Piecewise[], for example one could write a "function" that returns a different value in the evening than in the morning, which is obviously not a function in the mathematical sense, and thus can't be integrated. The third version of your example doesn't work (can't be plotted) because the syntax is incorrect: when /; is placed at the end, := must be used, not = . This can be easily discovered if one tries to evaluate that function with a specific numerical value.
From: Szabolcs Horvát on 12 Oct 2009 07:22 On 2009.10.11. 14:07, 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? > In short, /; is a programming construct that affects evaluation. Piecewise[] is used to represent a mathematical concept: piecewise functions. If you want to do mathematical operations like integration, then use Piecewise[]. Condition[] (/;) is a lot more general than Piecewise[], for example one could write a "function" that returns a different value in the evening than in the morning, which is obviously not a function in the mathematical sense, and thus can't be integrated. The third version of your example doesn't work (can't be plotted) because the syntax is incorrect: when /; is placed at the end, := must be used, not = . This can be easily discovered if one tries to evaluate that function with a specific numerical value.
From: Erik Max Francis on 13 Oct 2009 07:20 Szabolcs Horv=E1t wrote: > In short, /; is a programming construct that affects evaluation. > Piecewise[] is used to represent a mathematical concept: piecewise > functions. > > If you want to do mathematical operations like integration, then use > Piecewise[]. Condition[] (/;) is a lot more general than Piecewise[], > for example one could write a "function" that returns a different value > in the evening than in the morning, which is obviously not a function in > the mathematical sense, and thus can't be integrated. Got it! Thanks to you and David for responding. -- Erik Max Francis && max(a)alcyone.com && http://www.alcyone.com/max/ San Jose, CA, USA && 37 18 N 121 57 W && AIM/Y!M/Skype erikmaxfrancis God is love, but get it in writing. -- Gypsy Rose Lee
|
Next
|
Last
Pages: 1 2 3 Prev: undocumented feature: TableView Next: Import from web addresses fails |