I'm trying to understand how to calculate the volume of a recursive function containing an integral. To be precise; it is the volume V[n,r] of an n-dimensional sphere with radius r expressed as an integral of the expression for an (n-1)-dimensional sphere with radius y, i.e. V[n-1,y]. My first attemt was simply the following:
V[n_, r_] := If[n == 1, 2 r,
Assuming[r > 0, 2*Integrate[V[n - 1, Sqrt[r^2 - x^2]]
, {x, 0, r}]]
]
But it only works for n =1 and n=2, and returns undefined for n=3. After some searching on the web I found out that the problem could be that the radius from differens steps in the recursion gets mixed up. A fix for that is to introduce a module, like this:
V[n_, r_] := V[n, r] = If[n == 1, 2 r,
Assuming[r > 0,
Module[{x}, 2*Integrate[V[n - 1, Sqrt[r^2 - x^2]], {x, 0, r}]
]
]
]
Now the problem is the speed, V[2,r] is calulated in a blink but V[3,r] takes several seconds despite my attemt to use memoization. Anyone who can explain how to get this to work?
regards, Robert