UpmostScarab - 7 months ago 26

Python Question

Is there a way to make Symbol non-zero in sympy?

For example if I integrate:

`psi = a * cos( sqrt(2/mu)*x ) + b * sin( sqrt(2/mu)*x )`

Psi = integrate(psi, x)

it gives me two results one for mu == 0 and one for mu != 0. And I only need the second one.

Answer

Yes, you can do it with `mu = Symbol('mu', nonzero=True)`

.

```
from sympy import *
a,b,x = symbols('a b x')
mu = Symbol('mu', nonzero=True)
psi = a * cos( sqrt(2/mu)*x ) + b * sin( sqrt(2/mu)*x )
Psi = integrate(psi, x)
```

Now `Psi`

is a single expression.

Reference: assumptions.