Sympy allows you to define integer characters, but does not take into account their behavior

I have the following set of commands to execute a specific integral

n [2]: from sympy import *
init_printing()

x,L = symbols('x, L')
n = symbols('n', integer = True)

exp = sin((n+Rational(1,2))*pi*x/L)**2
integrate(exp, (x,0,L))

The result of these commands shown below:

enter image description here

From the first result it follows that n = -1/2, whence it follows that n is not an integer. What is the point at which an integer attribute refers to a character if it does not take it into account in operations, as shown above? How to make Sympy recognize that the first part of a piecewise result is not possible if n is an integer?

+4
source share
2 answers

, , . SymPy , L , .

,

>>> n = var('n', integer=True)
>>> L = var('L', nonzero=True)
>>> exp = sin((n+Rational(1,2))*pi*x/L)**2
>>> integrate(exp, (x,0,L))
L/2

!:-) ( , , , , L , , SymPy .)

/

+4

n , :

, , , . SymPy , .

, . , .

, n .

+2

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


All Articles