Any Other Method to Calculate Indefinite Integral Besides Using SymPy?

Hi all,

I use this code to calculate the indefinite integral of a complex trigonometric function:

# To compute an indefinite integral
using SymPy

# we can also use @vars x y z
x = symbols("x")

integrate((sin((x^(2) + 1)^(4)))^(3)*(cos(x^(2) + 1)^(4))*((x^(2)+1)^(3))*x)

it took long time, just like the computer is thinking and forgetting the trigonometric formula thus making it very long for me to wait. Maybe the problem is my processor or RAM is not good enough. If there is any other method to calculate the complex function of indefinite integral do tell me.

1 Like

You seem to have a typo with your integrand, I can’t be sure. The following has an integral identified using SymbolicNumericIntegration:

sin((x^(2) + 1)^(4))^(3)*(cos((x^(2) + 1)^(4))*((x^(2)+1)^(3)))*x

With SymPy it seems to need a bit of help with the substitution. This somewhat excessive pattern mirrors what might be done in a textbook:

using SymPy
@syms x dx v dv
constant(ex) = prod(x for x in ex.as_ordered_factors() if x.is_constant())
ex = sin((x^(2) + 1)^(4))^(3)*(cos((x^(2) + 1)^(4))*((x^(2)+1)^(3)))*x * dx

u = (x^2 + 1)^4
du = diff(u, x) * dx
c = constant(du)
duâ‚‘ = du/c
ex1 = subs(ex, duâ‚‘ => dv/c, u=>v, dv=>1)
integrate(ex1, v)(v => u)

the compiling is not even finished till now… I will try your code now then. Thanks @j_verzani

This is the solution from the textbook:

Capture d’écran_2022-11-24_02-35-09

Why is the code gives a solution of :
2 \sin^{4} v

how to know what is v ?

Did you try Julia?

julia> using Symbolics
julia> using SymbolicNumericIntegration

julia> @variables x
1-element Vector{Num}:

julia> expr=sin((x^(2) + 1)^(4))^(3)*(cos((x^(2) + 1)^(4))*((x^(2)+1)^(3)))*x
x*((1 + x^2)^3)*(sin((1 + x^2)^4)^3)*cos((1 + x^2)^4)

julia> @time integrate(expr)
 74.138733 seconds (323.74 M allocations: 16.519 GiB, 4.00% gc time, 77.46% compilation time: 0% of which was recompilation)
(0, x*(sin(1 + x^8 + 4(x^2) + 4(x^6) + 6(x^4))^3)*cos(1 + x^8 + 4(x^2) + 4(x^6) + 6(x^4)) + (x^7)*(sin(1 + x^8 + 4(x^2) + 4(x^6) + 6(x^4))^3)*cos(1 + x^8 + 4(x^2) + 4(x^6) + 6(x^4)) + 3(x^3)*(sin(1 + x^8 + 4(x^2) + 4(x^6) + 6(x^4))^3)*cos(1 + x^8 + 4(x^2) + 4(x^6) + 6(x^4)) + 3(x^5)*(sin(1 + x^8 + 4(x^2) + 4(x^6) + 6(x^4))^3)*cos(1 + x^8 + 4(x^2) + 4(x^6) + 6(x^4)), Inf)

I fixed my example to substitute back (and adjust the constant, which I had incorrect.)

Thanks @ufechner7 , but isn’t btime better to be used than time?

You change this

ex1 = subs(ex, duâ‚‘ => c*dv, u=>v, dv=>1)

into this

ex1 = subs(ex, duâ‚‘ => dv/c, u=>v, dv=>1)

what is the logic of dv/c and c*dv ?

Just that subs didn’t work with that constant 8 that comes out of the derivative. So it is taken out then put back in.