5

I have recently asked a question on math.stackexchange concerning how to compute volumes of intersecting hypercubes and hyperspheres to which I got an extremely helpful answer.

Now, I'm trying to utilize sage to generate some analytic solution for the lowest dimensionalities. With my very naive understanding of sage, the help of google and some trial & error, I came up with the following solution:

from sage.symbolic.integration.integral import definite_integral

R = var("R")
assume(R>0)
x = var("x")

V0(R) = 1
V = [V0]

for i in range(1,4):
    vlast = V[i-1]
    vnew(R) = definite_integral( vlast(R=sqrt(R**2 - x**2)),x,-min(R,1),min(R,1))
    V.append(vnew)        

print(V)

However, the output is not quite what I expected:

[R |--> 1, R |--> 2*R, R |--> pi*R^2, R |--> 4/3*pi*R^3]

Sage calculates the volumes of the n-dimesional spheres very nicely, but it somehow doesn't pick up the fact that the resulting function will be defined piecewise in R.

Is there something wrong about how I use the min function? Is there something wrong with how I define (or name) my variables? Where am I messing up?

Community
  • 1
  • 1
carsten
  • 1,315
  • 2
  • 13
  • 27
  • 1
    Maybe use `min_symbolic`. – kcrisman Nov 14 '16 at 02:11
  • That is already very helpful, but now sage seems unable to perform the integration:`[R |--> 1, R |--> 2*min(1, R), R |--> 2*integrate(min(1, sqrt(R^2 - x^2)), x, -min(1, R), min(1, R))]`. I already tried installing and using `fricas` to proceed, but now I get this: `Cannot find a definition or applicable library operation named min with argument type(s) Variable(R) PositiveInteger` - any further suggestions? – carsten Nov 14 '16 at 09:59

0 Answers0