For a physics application, I have to compute components of a rank-4 tensor, the Riemann tensor. I do this using a module (subroutine) which looks like this
Riemann[mu,nu,rho,sigma] = Module[{a=mu,b=nu,c=rho,d=sigma},Coefficient[(*expression1*), (*expression2*)]
(I have suppressed the details of expression 1 and expression 2 for clarity, as they are not relevant to my question. But it suffices to say that to extract the component of the tensor, I am picking out the coefficient of some term in another expression. This extraction works, as I have tested it for many cases.)
So when I call Riemann[1,2,3,4] (say), I get an expression, which is correct.
However, what I want is to dump it into an array, using for example:
dim = 11
RiemannArray = Array[ Riemann[#1,#2,#3,#4]&, {dim,dim,dim,dim} ]
If this worked, I would have been able Riemann[mu,nu,rho,sigma] stored in RiemanArray[[mu,nu,rho,sigma]].
However, what I get is a series of errors of the form:
Coefficient::ivar: 0 is not a valid variable. General::stop: Further output of Coefficient::ivar will be suppressed during this calculation.
Even if I remove the evaluation of the tensor components from a module and put it as an inline statement inside Array[...], I get the same set of errors.
Is there a way out of this?
Note that if I ignore these errors, the array seems to have been created.
Coefficient
in your definition ofRiemann
, not from the creation of your array which, as you say, seems to work fine. Something odd might be going on with your definition ofRiemann
, which you could clean up asRiemann[mu_, nu_, rho_, sigma_] := Module[ *etc* ]
. $\endgroup$::ivar
error is often generated when a variable has inadvertently been given a value (search for "ivar" on this site). That is, somewhere your code is trying use0
as a variable. Your error messageCoefficient::ivar
indicates that this is occurring inCoefficient
. I would guess the problem is with yourexpression2
, leading to something along the lines ofCoefficient[(x + y)^2, 0]
(for certain entries in your array), which generates the exact same error message as you're getting. $\endgroup$