Ask Your Question
0

Integrating complicated expression with two variables

asked 2017-06-30 13:22:19 -0500

anonymous user

Anonymous

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 flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2017-06-30 14:54:49 -0500

mforets gravatar image

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).

edit flag offensive delete link more
0

answered 2017-06-30 15:52:06 -0500

kcrisman gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-06-30 13:22:19 -0500

Seen: 60 times

Last updated: Jun 30