Sympy integration

I am trying to perform the following integration using sympy;

x = Symbol('x')
expr = (x+3)**5
integrate(expr)

The answer I expect is the following:

enter image description here

But what comes back:

enter image description here

The following code works in MATLAB:

syms x
y = (x+3)^5;
int(y)

I'm not sure what I'm doing wrong to accomplish this using sympy.

+4
source share
1 answer

This is actually a common problem observed in Calculus, where for these types of polynomial expressions you get two answers. Coefficients for each of the degrees xexist, but there is no constant coefficient between them.

, , , .

  • - , u = x+3, u. (1/6)*(x + 3)^6 + C, .

  • , .


MATLAB :

>> syms x;
>> out = int((x+3)^5)

out =

(x + 3)^6/6

-, , , , , :

>> expand(out)

ans =

x^6/6 + 3*x^5 + (45*x^4)/2 + 90*x^3 + (405*x^2)/2 + 243*x + 243/2

sympy :

In [20]: from sympy import *

In [21]: x = sym.Symbol('x')

In [22]: expr = (x+3)**5

In [23]: integrate(expr)
Out[23]: x**6/6 + 3*x**5 + 45*x**4/2 + 90*x**3 + 405*x**2/2 + 243*x

, , . , , , MATLAB.

, , sympy, , . , sympy :

>> syms x;
>> out = expand((x+3)^5)

out =

x^5 + 15*x^4 + 90*x^3 + 270*x^2 + 405*x + 243

>> int(out)

ans =

x^6/6 + 3*x^5 + (45*x^4)/2 + 90*x^3 + (405*x^2)/2 + 243*x

, . , , , .


DSM, manual=True integrate, , , :

In [26]: from sympy import *

In [27]: x = sym.Symbol('x')

In [28]: expr = (x+3)**5

In [29]: integrate(expr, manual=True)
Out[29]: (x + 3)**6/6
+7

Source: https://habr.com/ru/post/1617658/


All Articles