Re: Mathematica have an 'Assume' type syntax/command?
- To: mathgroup at smc.vnet.net
- Subject: [mg33082] Re: Mathematica have an 'Assume' type syntax/command?
- From: adam.smith at hillsdale.edu (Adam Smith)
- Date: Fri, 1 Mar 2002 06:51:43 -0500 (EST)
- References: <a5htib$hsu$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Mathematica has the capability of adding assumptions to the integral via Assumptions->{}. However, it is not perfect as shown below in the Mathematica equivalent of what you did in Maple: Integrate[x^2*Sin[n*Pi*(x/a)]^2, {x, 0, a}, Assumptions -> {Element[n,Integers], n > 0,a>0}] If[Im[n/a] == 0, (a^3*(4*n^3*Pi^3 - 6*n*Pi*Cos[2*n*Pi] + (3 - 6*n^2*Pi^2)*Sin[2*n*Pi]))/(24*n^3*Pi^3), Integrate[x^2*Sin[(n*Pi*x)/a]^2,{x, 0, a}]] The output is if the condition Im[n/a]==0 is true, then whatever appears in the 2nd position. If false, the answer is the third position. I say it the use of assumptions in not perfect, because doing the integral without assumptions gives In[1]:= Integrate[x^2*Sin[n*Pi*(x/a)]^2, {x, 0, a}] Out[1]= a^3/6 - (a^3*Cos[2*n*Pi])/(4*n^2*Pi^2) - (a*(-a^2 + 2*a^2*n^2*Pi^2)*Sin[2*n*Pi])/ (8*n^3*Pi^3) Which then simplifies using the Simplify[] with conditions In[26]:= Simplify[Integrate[x^2*Sin[n*Pi*(x/a)]^2, {x, 0, a}], {Element[n,Integers]}] Out[26]= (1/12)*a^3*(2 - 3/(n^2*Pi^2)) The final form is fine as long as n is not zero. It would imply that as n=0 the thing "blows up". However, the Simplify fails for the case of n=0 as can be seen by looking at the limit of the integral as n approaches zero. In[27]= Limit[a^3/6 - (a^3*Cos[2*n*Pi])/(4*n^2*Pi^2) - (a*(-a^2 + 2*a^2*n^2*Pi^2)*Sin[2*n*Pi])/(8*n^3*Pi^3),n->0] Out[27]= 0 This can be traced to the similar problem in Simplify for Sin[n Pi]/n In[30]:= Simplify[Sin[n Pi]/n,Element[n,Integers]] Out[30]= 0 This is true except for n=0, in which case the answer = Pi. Obviously, somewhere in the Simplify code Mathematica recognizes that Sin[n Pi] = 0 for integers, but it does not check that the denominator is not 0. I wrote to Mathematica about this and got back a long answer saying it was not a bug but a limitation having to do with "problems with generalicity" (my paraphrase from memory). My interpretation of "generalicity" was that it would be impossible to anticipate all the various limiting conditions that could come up for Simplify to handle and that trying to build a huge number of special cases would make the Simplify with conditions routine much too slow. Having said that, I still think that this is a deficiency in Simplify. Maybe others feel the same way, let Mathematica know about it. Until it changes, I strongly recommend that people check any special cases with the Limit[] method. Adam Smith This is fine in your case since "Flip Flippy" <flip at safebunch.com> wrote in message news:<a5htib$hsu$1 at smc.vnet.net>... > Hi All, > > I saw this on sci.math and was wondering how an 'assume' type function > can be done in Mathematica. > > Does one exist, or is there a way to emulate one? > > Here was the problem. > > After running the following code in maple: > > assume(n>0,n,integer); > int(x^2*(sin(n*Pi*x/a))^2,x=0..a); > > Any thoughts? Thank you, Flip