# construct matrix by applying derivatives to another matrix

Say you have a vector like the following

NN[\[Xi]_, \[Eta]_] := ( {
{1/4 (1 - \[Xi]) (1 - \[Eta])},
{1/4 (1 + \[Xi]) (1 - \[Eta])},
{1/4 (1 + \[Xi]) (1 + \[Eta])},
{1/4 (1 - \[Xi]) (1 + \[Eta])}
} )


and you would like to construct a matrix of 2 columns, where the first column is the result of applying the derivative to the vector with respect to \[Xi] and the second column with respect to \[Eta]. I tried this:

DNN[\[Xi]_, \[Eta]_] := ( {
{\!$$\*SubscriptBox[\(\[PartialD]$$, $$\[Xi]$$]$$NN[\[Xi], \ \[Eta]]$$\), \!$$\*SubscriptBox[\(\[PartialD]$$, $$\[Xi]$$]$$NN[\[Xi], \[Eta]]$$\)}
} )


But then I get extra brackets (see figure).

Is there an easier way to do this than the brute force approach where I construct the matrix as follows?

DNN[\[Xi]_, \[Eta]_] := ( {
{\!$$\*SubscriptBox[\(\[PartialD]$$, $$\[Xi]$$]$$\(NN[\[Xi], \ \[Eta]]$$[$$[1]$$]\)\), \!$$\*SubscriptBox[\(\[PartialD]$$, $$\[Eta]$$]$$\(NN[\[Xi], \[Eta]]\$$[$$[1]$$]\)\)},
{\!$$\*SubscriptBox[\(\[PartialD]$$, $$\[Xi]$$]$$\(NN[\[Xi], \ \[Eta]]$$[$$[2]$$]\)\), \!$$\*SubscriptBox[\(\[PartialD]$$, $$\[Eta]$$]$$\(NN[\[Xi], \[Eta]]\$$[$$[2]$$]\)\)},
{\!$$\*SubscriptBox[\(\[PartialD]$$, $$\[Xi]$$]$$\(NN[\[Xi], \ \[Eta]]$$[$$[3]$$]\)\), \!$$\*SubscriptBox[\(\[PartialD]$$, $$\[Eta]$$]$$\(NN[\[Xi], \[Eta]]\$$[$$[3]$$]\)\)},
{\!$$\*SubscriptBox[\(\[PartialD]$$, $$\[Xi]$$]$$\(NN[\[Xi], \ \[Eta]]$$[$$[4]$$]\)\), \!$$\*SubscriptBox[\(\[PartialD]$$, $$\[Eta]$$]$$\(NN[\[Xi], \[Eta]]\$$[$$[4]$$]\)\)}
} )

• Is this what you want DNN[\[Xi]_, \[Eta]_] := Transpose[{\!$$\*SubscriptBox[\(\[PartialD]$$, $$\[Xi]$$]$$NN[\[Xi], \[Eta]]$$\), \!$$\*SubscriptBox[\(\[PartialD]$$, $$\[Eta]$$]$$NN[\[Xi], \[Eta]]$$\)}] – Hubble07 Sep 28 '15 at 17:42

DNN[ξ_, η_] := D[Flatten@NN[ξ, η], {{ξ, η}}]
DNN[ξ, η] // MatrixForm


(The first column is w.r.t ξ and the second is w.r.t to η. In the question both are computed w.r.t to ξ, although the wording indicates that both partial derivatives are desired.)

You can use Flatten to remove the extra parentheses:

Transpose[Flatten[DNN[ξ, η], 1]];
MatrixForm[%]


• I ended up using ArrayFlatten. – Alejandro Marcos Aragon Sep 28 '15 at 19:27
Transpose[Inner[D[#1, #2] &, Transpose[NN], {\[Xi]_, \[Eta]_}, List]]