Ask Your Question
0

Strange problem with double integrals

asked 2013-03-05 13:05:09 +0100

ebs gravatar image

updated 2013-03-05 13:08:47 +0100

I need to calculate a double of integral a large expression numerically. But, I found a strange error. The code:

def doubleIntegral():
    def f2(theta):
        def f1(phi):
            return theta*phi/pi
        return numerical_integral(f1,0,2*pi)[0]
    return numerical_integral(f2,0,pi)

works. but

a = theta*phi/pi  # Suppose this is a huge expression that came out of previous calculations

def doubleIntegral():
    def f2(theta):
        def f1(phi):
            return a
        return numerical_integral(f1,0,2*pi)[0]
    return numerical_integral(f2,0,pi)

doesn't work

unable to simplify to float approximation
unable to simplify to float approximation
.
.
.

What is going on? And how can I fix this?

edit retag flag offensive close merge delete

Comments

Try doing an internet search for using lambda functions for this. http://ask.sagemath.org/question/68/double-integral might be helpful along these lines...

kcrisman gravatar imagekcrisman ( 2013-03-05 13:30:15 +0100 )edit

my function doubleIntegral does the same thing as what that nestled numerical_integral with lambda functions (from that question) does. It has the exact same problem. Trying the internet search...

ebs gravatar imageebs ( 2013-03-05 13:41:30 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2013-03-05 14:38:26 +0100

ppurka gravatar image

In the second example function, you are returning a from the innermost loop, but a is a symbolic expression. In the first example, what you return from the innermost loop is just a number evaluated at theta and phi. What happens if you instead use return a.subs(theta=theta, phi=phi) in the second example?

edit flag offensive delete link more

Comments

Oh! I get it. I also found dblquad in scipy.integrate (instead of this function) which seems to be faster. ty :)

ebs gravatar imageebs ( 2013-03-06 02:05:49 +0100 )edit

Your Answer

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

Add Answer

Question Tools

Stats

Asked: 2013-03-05 13:05:09 +0100

Seen: 281 times

Last updated: Mar 05 '13