Question: Automatically generate a function of an array or vector

As an engineer I typically do a lot of work with matrices and oftentimes symbolic matrices. I might generate a symbolic matrix and perform some computations that creates a function of the symbolic elements of the matrix. I now want to turn those symbolic expressions into a procedure that is a function of the matrix array input. How can this be done? There does not appear to be any simple solution. This task is so obvious and so common that I'm shocked there is no simple answer. Here is a trivial example The symbolic matrix with( LinearAlgebra) : U := Matrix(2,2, symbol=u) ; r := Determinant(U) ; Now please make r a function of U with U as the matrix input. Does this work? f := unapply(r,U) ; Error, (in unapply) variables must be unique and of type name Nope, that would be too obvious. Wait this should work, since r is a global in this function right? f := proc(U :: Matrix(2,2,numeric)) ; r ; end proc ; Q := Matrix([[1,2],[3,4]],datatype=numeric) ; f(Q) ; u[1,1]*u[2,2]-u[1,2]*u[2,1] The output is simply the original symbolic expression r. There is no substitution into u_i,j variables. Thats because basically the input U to the procedure is a local variable whereas the expression in r assumed global u_i,j. I think the only hope is to turn the expression into a string and then do a bunch of string manipulations and concatenations to generate the string representing the procedure. After that one can do a parse. This approach is not particularly elegant. The need for this arises from the situation where one is computing very complicated matrix expressions symbolically and then trying to turn those expressions ultimately into C code for use in numerical software. Imagine the situation where these expressions are dependent on 100 or so input variables representing the elements of arrays or matrices. In this case I don't want to enter all the variables at the start of C code by hand. If we want Maple to be useful for something other than just teaching, it has to be able to perform tasks like this.
Please Wait...