Computing Symbolic Integral with SymPy

Hi all,

I just want to know why the solution in the manual for number 17 and 18 are different with the one I computed with Julia?

Capture d’écran_2023-02-28_11-59-29

using SymPy
@syms x, v, z, t

v1(v) = (6v+9)/(3v^2 + 9v)
v2(z) = z/(2z^2 + 8)
v3(x) = (2*log(x))/x
v4(x) = -1/(x*log(x)^2)
v5(x) = (x^4)/(2x^5 + pi)
v6(t) = (t+1)/(2t^2 + 4t + 3)
v7(x) = (x^2)/(x-1)
v8(x) = (x^2 + x)/(2x - 1)
v9(x) = (x^4)/(x + 4)
v10(x) = (x^3 + x^2)/(x + 2)

V1 = integrate((v1(v)), (v))
V2 = integrate((v2(z)), (z))
V3 = integrate((v3(x)), (x))
V4 = integrate((v4(x)), (x))
V5 = integrate((v5(x)), (x, 0, 3))
V6 = integrate((v6(t)), (t, 0, 1))
V7 = integrate((v7(x)), (x))
V8 = integrate((v8(x)), (x))
V9 = integrate((v9(x)), (x))
V10 = integrate((v10(x)), (x))

println("Computing symbolic integral and definite integral")
println("a.  ", V1)
println("b.  ", V2)
println("c.  ", V3)
println("d.  ", V4)
print("e.  ", V5)
println(" = ", V5.evalf())
print("f.  ", V6)
println(" = ", V6.evalf())
println("g.  ", V7)
println("h.  ", V8)
println("i.  ", V9)
println("j.  ", V10)

why the integral of SymPy does not have + C ?

Why would it be necessary? The C just indicates the generic solution. Maxima and Axiom don’t return C.

1 Like

What @Paulo_Jabardo said, it’s a basic fact about integration that any integral is defined up to a constant. If you differentiate that constant you get zero, so you can have any C and it will still give you the integrand after differentiation. I believe some Computer Algebra Systems (Maxima is an example) would just assume the users know that and define it as C=0.
In the real world, for some problems (in Physics, for example) the constant C actually matters because of boundary conditions, it’s common when solving PDE’s for fields through methods like assuming a function f(x,y,z) is of the form f(x,y,z) = X(x)Y(y)Z(z). In essence, you leave that C in the solution as a parameter and then define it based on your boundary conditions.

1 Like