How to Use SymPy to calculate Definite Integrals with Symbols of Constant?

Hi all,

I am using SymPy to try calculate this

\int_{A}^{B} ax+b \ dx

the function f(x) = ax+b where a and b are constant in symbolics.
The integral is definite but, the interval of the integral is in symbolics too A and B.

I use this code, try them:

using SymPy

x, y, z = symbols("x y z")

A, B = symbols("A B")

integrate(ax+b, (x, A, B))

but it gets error:
LoadError: UndefVarError: ax not defined

  1. You haven’t declared a,b as symbols
  2. You need to write a*x. Leaving out the multiplication operator works only with numbers. Anything else would be ambiguous.
julia> integrate(a*x+b, (x, A, B))
   2            2        
  A β‹…a         B β‹…a      
- ──── - Aβ‹…b + ──── + Bβ‹…b
   2            2        
1 Like

Alright it works now, but I have another further question for new topic about this.