UpmostScarab - 1 year ago 69

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 Source

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.