I am trying to write a function that returns a list of pure functions. The last step in the function, is to multiply the list of pure functions by a list of scalars (i.e. matrix multiplication). When I try to evaluate the resulting functions, it does not work.
Code
calcShapeFunctions[nnpe_] := Module[
{m, xiCoord, etaCoord, p, c},
m = Array[
Function[{xi,
eta}, {1, xi, eta, xi*eta, xi^2, eta^2, xi^2*eta, xi*eta^2,
xi^2*eta^2}[[#]]] &, nnpe];
xiCoord = {-1, 1, 1, -1, 0, 1, 0, -1, 0};
etaCoord = {-1, -1, 1, 1, -1, 0, 1, 0, 0};
p = m[[1 ;; nnpe]];
c = Array[Through[p[xiCoord[[#]], etaCoord[[#]]]] &, nnpe];
Return[p.Inverse[c]];
];
Incorrect Output
Through[calcShapeFunctions[3][x, y]]
returns:
{(1/2 Function[{xi, eta}, {1, xi, eta, xi eta, xi^2, eta^2, xi^2 eta, xi eta^2, xi^2 eta^2}[[1]]] - 1/2 Function[{xi, eta}, {1, xi, eta, xi eta, xi^2, eta^2, xi^2 eta, xi eta^2, xi^2 eta^2}[[2]]])[x, y], (1/2 Function[{xi, eta}, {1, xi, eta, xi eta, xi^2, eta^2, xi^2 eta, xi eta^2, xi^2 eta^2}[[2]]] - 1/2 Function[{xi, eta}, {1, xi, eta, xi eta, xi^2, eta^2, xi^2 eta, xi eta^2, xi^2 eta^2}[[3]]])[x, y], (1/2 Function[{xi, eta}, {1, xi, eta, xi eta, xi^2, eta^2, xi^2 eta, xi eta^2, xi^2 eta^2}[[1]]] + 1/2 Function[{xi, eta}, {1, xi, eta, xi eta, xi^2, eta^2, xi^2 eta, xi eta^2, xi^2 eta^2}[[3]]])[x, y]}
Desired Output
Through[calcShapeFunctions[3][x, y]]
should return:
{1/2 - x/2, x/2 - y/2, 1/2 + y/2}
Further Thoughts
Assuming we can get this to work, how would I go about obtaining the derivatives of the pure function with respect to one of its independent variables (xi and eta)?
m = m[[{1}, ;; nnpe]];? I'm confused on howPartis working there. – Matthew Apr 05 '13 at 01:03Derivativeto work onxiandeta(#1and#2), won't you need something likeEvaluate[mev[#1, #2].ic] &in the body ofWith? – Michael E2 Apr 05 '13 at 01:09D[calcFn2[3][x, y], y]does what I need it to do. – Matthew Apr 05 '13 at 01:13D[.., y]calculates the derivative of the composition with respect toy, not the derivative ofcalcFn2[3]with respect toetaper se though, which would beDerivative[0,1][calcFn2[3]]. For instance,Derivative[0,1][calcFn2[3]][1,2]orDerivative[0,1][calcFn2[3]][x-y,2y]could not be done by simply substitutingD[.., y]. Of course, in each case, it's possible to makeDwork one way or another. – Michael E2 Apr 05 '13 at 01:24Evaluatecommand, but it did not work. – Matthew Apr 09 '13 at 01:53