Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
1

How to solve for volume

asked 11 years ago

Lunatic gravatar image

updated 11 years ago

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)
Preview: (hide)

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 ( 11 years ago )

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 ( 11 years ago )

1 Answer

Sort by » oldest newest most voted
1

answered 11 years ago

kcrisman gravatar image

updated 11 years ago

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 - rdrdθ, 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?

Preview: (hide)
link

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: 11 years ago

Seen: 405 times

Last updated: Jan 11 '14