# Integrating complicated expression with two variables

I am trying to compute a double integral with respect to variables x and y. I first compute the integral with respect to the variable x:

first_int = integral(h, x, 1, 5)


which gives me as an output :

integrate(1/(log(abs(x^4 + 13*x^3*y - 30*x^2*y^2 + 2*x*y^3 - 3*x^2*y + x*y^2 + x^2 + x*y + y^2 + 2*x + 13))^log(abs(x^4 + 13*x^3*y - 30*x^2*y^2 + 2*x*y^3 - 3*x^2*y + x*y^2 + x^2 + x*y + y^2 + 2*x + 13))), x, 1, 5)


instead of an expression now only depending on the second variables y.

Then, when I try to integrate with respect to the second variable y by writing

second_int = first_int.integrate(y, 1, 5)


I get the following output:

integrate(integrate(log(abs(x^4 + 13*x^3*y - 30*x^2*y^2 + 2*x*y^3 - 3*x^2*y + x*y^2 + x^2 + x*y + y^2 + 2*x + 13))^(-log(abs(x^4 + 13*x^3*y - 30*x^2*y^2 + 2*x*y^3 - 3*x^2*y + x*y^2 + x^2 + x*y + y^2 + 2*x + 13))), x, 1, 5), y, 1, 5)


finally if I try to write (to get the numerical value)

second_int = n(first_int.integrate(y, 1, 5))


I get the error message ValueError: The function to be integrated depends on 2 variables (x, y), and so cannot be integrated in one dimension. Please fix additional variables with the 'params' argument

I have tried integrating the same type of function when there is only one variable and the integration works fine, so I am thinking something goes wrong in the double integration but I can't figure out what!

Thanks.

edit retag close merge delete

Sort by » oldest newest most voted

This is an approach for a numerical solution using mpmath:

sage: x, y = var('x, y')
sage: h = 1/(log(abs(x^4 + 13*x^3*y - 30*x^2*y^2 + 2*x*y^3 - 3*x^2*y + x*y^2 + x^2 + x*y + y^2 + 2*x + 13))^log(abs(x^4 + 13*x^3*y - 30*x^2*y^2 + 2*x*y^3 - 3*x^2*y + x*y^2 + x^2 + x*y + y^2 + 2*x + 13)))
sage: from sage.ext.fast_callable import fast_callable
sage: hh = fast_callable(h, vars=[x, y])
sage: import mpmath as mp
sage: print(mp.quad(hh, [1, 5], [1, 5]))
(124.078805233118 + 10.8586740662171j)


A good reference on integration, with many examples, is Ch. 14 of Calcul Mathematique avec Sage (link to English translation).

more

Yeah, this sort of thing is tricky because there may not be a closed form solution. See this question and this question on this site for just two examples. I suppose that some variant of this answer using numerical_integral might work.

more