I have the following situation. I will first post the code and then explain what I'm trying to do and what is going wrong
F[1,2] = Function[{x,y}, x^2 E[1] + y^2 E[2]];
coords = {x,y};
coeff[i_][a_, b_][x_,y_] := Coefficient[F[a, b][x,y], E[i]];
derF[a_, b_][x_,y_] := Table[D[coeff[i][a, b][x,y], coords[[j]]], {i, 1, 2}, {j, 1, 2}]
The idea is this: I'm defining some collection of functions of $(x,y)$ that I'm defining as F[a,b]
. Each of the functions is a linear combination of the variables E[1]
and E[2]
.
When I define coeff[i][a,b]
I want to extract the function that appears as the coefficient of E[i]
in F[a,b]
. Then I want to define a matrix of functions derF[a,b]
that contains the derivatives of the coefficients of E[1]
and E[2]
appearing in F[a,b]
.
My problem is that I want derF[a,b]
to be a function in the sense that I can put whatever variable as argument. So for example, I would like to be able to use derF[a,b][t,s]
and get the matrix with the functions as functions of $(t,s)$.
The problem is that if I use this code and compute derF[a,b][t,s]
I get zero. And I do understand why: Mathematica is basically taking the derivative of a function of $(t,s)$ with respect to $(x,y)$. That's not what I want. I want it to first evaluate the derivative and then substitute the variable, but I have no idea how to achieve this.
So, how do I fix this code to achieve the right intent?
E[i]
are always eitherE[1]
orE[2]
? $\endgroup$F[a, b][x, y]
, but you've only definedF
withF[1,2]
. Does that meana
andb
will always be1
or2
? Or is that your actual question--how to defineF
for anya
andb
? $\endgroup$f1 = Function[{x, y}, x^2 e[1] + y^2 e[2]]
orf2[a_, b_] := Function[{x, y}, x^2 e[a] + y^2 e[b]]
. Maybe you can give a concrete example of what you expect forf[a,b]
for some specifica
andb
. And then what you expect forcoeff[i][a,b][x,y]
for some specifici
,a
, andb
. $\endgroup$E
is a pre-defined symbol, so you may want to avoid it. $\endgroup$e[i]
instead. It is always just eithere[1]
ore[2]
. Now, I don't have a general formula forF[a,b]
as a function ofa
andb
. I have manually definedF[a, b]
fora = 1,2,3
andb=1,2,3
, but here I just put one of them as an example. The point is that I have a $3\times 3$ matrix of functions of{x,y}
which are linear combinations of the symbolse[1]
ande[2]
$\endgroup$