Difficulties in solving recursive integrals with sage

I recently asked a question about math.stackexchange regarding how to calculate volumes of intersecting hypercubes and hyperspheres , to which I received an extremely useful answer.

Now I'm trying to use sage to create some analytic solution for the lowest dimensions. Thanks to my naive understanding of the sage, the help of Google and some trial and 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 conclusion is not quite what I expected:

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

Sage calculates volumes of n-dimensional spheres very well, but somehow does not understand that the resulting function will be defined piecewise in R.

Is there something wrong with how I use the min function? Is there something wrong with the way I define (or call) my variables? Where did I mess?

+5
source share

Source: https://habr.com/ru/post/1259692/


All Articles