On Thu, Mar 18, 2010 at 1:40 PM, Ondrej Certik <[email protected]> wrote:
> Hi Catherine!
>
> On Thu, Mar 18, 2010 at 1:23 PM, Catherine Kehl <[email protected]> wrote:
>> This is a specific problem, rather than an interesting theory
>> question, but I'm hoping someone can help untangle me a bit.
>>
>> A hobby of mine the last bit has been working through Apostol's
>> Calculus, and thereby remedying some of the deficits in my math
>> education. (This is a very inexpensive hobby, amortizing the cost of
>> the books over the time you put into it, if you do all the problems.)
>>
>> Anyhow, while banging my head against, this problem*:
>>
>> Use integration by part to derive the following formula:
>>
>> \int(a^2-x^2)^n dx = \frac {x(a^2-x^2)} {2n+1} + \frac {2a^2n} {2n+1}
>> \int(a^2-x^2)^{n-1} dx + C
>>
>> (I'm hoping tex is enough of a lingua franca to pass muster here? This
>> is 5.10.15a, on page 221...)
>>
>> Anyhow, having not found my way through this, I decided to run it
>> though sympy as there are a (very) few misprints in Apostol... and
>> hey, I've been wanting to play more with sympy.
>>
>> Having set a=5, and n=7, c=11 and d=13 I gave it:
>>
>> In [29]: s.integrate((a**2-x**2)**n, (x, c, d))
>>
>> to which it returned:
>>
>> Out[29]: -5757254575990452224/6435
>>
>> I then fed it:
>>
>> In [31]: (d*(a**2-d**2)**n)/(2*n+1)-(c*(a**2-c**2)**n)/(2*n
>> +1)+(2*a**2*n)/(2*n+1)*s.integrate((a**2-x**2)**(n-1), (x, c, d))
>>
>> for which I received:
>>
>> Out[31]: -2693709139701405314/3003
>>
>> (You will note that these values, while vaguely close, are not equal.)
>
> This is what I got:
>
>
> In [2]: a = 5; n = 7; c = 11; d = 13
>
> In [3]: integrate((a**2-x**2)**n, (x, c, d))
> Out[3]:
>  5757254575990452224
> - ───────────────────
>          6435
>
> In [4]: (d*(a**2-d**2)**n)/(2*n+1)-(c*(a**2-c**2)**n)/(2*n
>   ...: +1)+(2*a**2*n)/(2*n+1)*integrate((a**2-x**2)**(n-1), (x, c, d))
> Out[4]: -894678255787172.
>
>
>
> So in [4] I got a different number than you did.  SymPy should be able
> to do most of the stuff from calculus books, so I'll investigate this
> later, unless someone beats me to it.

Found it. Here is what you have to do:

In [5]: a = S(5); n = S(7); c = S(11); d = S(13)

In [6]: integrate((a**2-x**2)**n, (x, c, d))
Out[6]:
  5757254575990452224
- ───────────────────
          6435

In [7]: (d*(a**2-d**2)**n)/(2*n+1)-(c*(a**2-c**2)**n)/(2*n
+1)+(2*a**2*n)/(2*n+1)*integrate((a**2-x**2)**(n-1), (x, c, d))
Out[8]:
  5757254575990452224
- ───────────────────
          6435


The problem with Python is that 1/2 returns 0, so you need to use
S(1)/2 to let Python know that S(1) is a SymPy integer and then all is
fine.

Ondrej

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to