# How to solve for volume

I have a function that looks like this:

def f1(x,y):
return max(0, a * (r - x*x-y*y))


a and r are constants, with r being the radius. Given the radius, how do I get sage to tell me what a needs to be so that the volume of the function is 1?

For example, solution for radius of 1.5 is 0.28294212105225836:

r = 1.5
a = 0.28294212105225836
dblquad(lambda x, y: f1(x,y), -r, r, lambda x: -r, lambda y: r)
(1.0000000008272796, 4.581186036178006e-09)

edit retag close merge delete

Just a brief note - if you leave a and r symbolic, you will probably want max_symbolic; if a and r always will have numeric values this isn't a problem (though I assume for your case it may be symbolic).

yes, I know about max_symbolic. I've also tried getting sage to solve this symbolically and numerically, but I don't know what I'm doing wrong.

Sort by » oldest newest most voted

My first thought would be to switch your integral to polar coordinates so you don't need the max bit at all.

sage: r = 1.5
sage: var('a')
a
1.125*pi*a
sage: solve(_==1,a)
[a == 8/9/pi]
sage: n(_.rhs())
0.282942121052258


I think I did the change of coordinates right - $r dr d\theta$, right?

Now, this doesn't answer the more general question of how to do this with a max and a double numerical integral, where I would suggest using find_root - or just using Scipy in general, perhaps, since you are already using it, if you really do not need the symbolic capabilities; the syntax may end up more natural, who knows?

more