Ask Your Question
1

How to solve for volume

asked 2014-01-10 15:14:43 -0600

Lunatic gravatar image

updated 2014-01-10 15:15:18 -0600

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

Comments

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

kcrisman gravatar imagekcrisman ( 2014-01-10 15:31:34 -0600 )edit

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.

Lunatic gravatar imageLunatic ( 2014-01-10 15:40:40 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-01-11 14:22:52 -0600

kcrisman gravatar image

updated 2014-01-11 14:23:18 -0600

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('rad,theta')
(rad, theta)
sage: var('a')
a
sage: integrate(integrate(a*(r - rad^2)*rad,theta,0, 2*pi),rad,0,sqrt(r))
1.125*pi*a
sage: solve(_==1,a)
[a == 8/9/pi]
sage: n(_[0].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?

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

Stats

Asked: 2014-01-10 15:14:43 -0600

Seen: 105 times

Last updated: Jan 11 '14