Can I define a function over many "external" constants?
Basically I have a function that needs to access "external" but constant values. For example, simplified:
The as
are constant but I don't know n
beforehand. My goal is to use SAGE to calculate the integral and derivative of a larger function. I know that there is a symbolic sum
function, but I am not sure if it is possible to use the index to refer to something undefined and "external" to the function.
By now I have stumbled over the function
... function which I misuse to serve my purpose (can I link a sagecloud notebook here?):
%var x, y, z, i, n
ai = function('ai')
xi = function('xi')
yi = function('yi')
zi = function('zi')
gauss(a,x,y,z) = a * e^(-(x^2+y^2+z^2)/2)
f(x,y,z) = (sum( gauss(ai(i),x-xi(i), y-yi(i), z-zi(i)) ,i,1,n))^2
integral(integral(integral(f,x),y),z)
Which results in:
(x, y, z) |--> integrate(integrate(integrate(sum(ai(i)*e^(-1/2*x^2 - 1/2*y^2 - 1/2*z^2 + x*xi(i) - 1/2*xi(i)^2 + y*yi(i) - 1/2*yi(i)^2 + z*zi(i) - 1/2*zi(i)^2), i, 1, n)^2, x), y), z)
Does this mean SAGE is not able to integrate this symbolically?
If you define
you should get the result without the "(x, y, z) |-->", which probably more properly expresses what you intend.
I think your hypothesis that SAGE doesn't know how to integrate this is also correct, since simpler examples using the same features do work:
That's a shame :(
Have you tried specifying a specific value of n, by the way? If you define, for instance
and then run your example, you do get an expression in terms of "erf" (which is the best you can hope for). So I think the problem is actually more that sage (or really maxima, which sage relies on for these things) does not know how to expand sum(...)^2 in this case, because the integration isn't the problem. If you manually expand the square, you'd be able to find an answer that doesn't explicitly mention integrals anymore.
@nbruin: yep I tried that. And that actually brought me a step closer to the solution. Basically I could extrapolate the real integral from several different
n
s ;)