I'm trying to create a simple function that generates a transformation matrix from the partial derivatives of two coordinate systems. It currently works when I have it written like this:
x[r_, theta_] = r*Cos[theta];
y[r_, theta_] = r*Sin[theta];
transformationMatrix[r_, theta_] =
{{D[x[r, theta], r], D[x[r, theta], theta]},
{D[y[r, theta], r], D[y[r, theta], theta]}};
In[123]:= transformationMatrix[0.3, 0.5]
Out[123]= {{0.877583, -0.143828}, {0.479426, 0.263275}}
But I want the function to work with vectors, not scalars, so I change it to this:
x[xPrime_] = xPrime[[1]]*Cos[xPrime[[2]]];
y[xPrime_] = xPrime[[1]]*Sin[xPrime[[2]]];
transformationMatrix[xPrime_] =
{{D[x[xPrime], xPrime[[1]]], D[x[xPrime], xPrime[[2]]]},
{D[y[xPrime], xPrime[[1]]], D[y[xPrime], xPrime[[2]]]}};
transformationMatrix[{0.3, 0.5}]
and I get a bunch of errors that say:
Part::partd: Part specification xPrime[[1]] is longer than depth of object. >>
Part::partd: Part specification xPrime[[2]] is longer than depth of object. >>
Part::partd: Part specification xPrime[[1]] is longer than depth of object. >>
Part::partd: Part specification xPrime[[2]] is longer than depth of object. >>
Fine, so I'll try deferring the evaluation with this:
x[xPrime_] := xPrime[[1]]*Cos[xPrime[[2]]];
y[xPrime_] := xPrime[[1]]*Sin[xPrime[[2]]];
transformationMatrix[xPrime_] :=
{{D[x[xPrime], xPrime[[1]]], D[x[xPrime], xPrime[[2]]]},
{D[y[xPrime], xPrime[[1]]], D[y[xPrime], xPrime[[2]]]}};
transformationMatrix[{0.3, 0.5}]
And I get this:
General::ivar: 0.3` is not a valid variable. >>
General::ivar: 0.5` is not a valid variable. >>
General::ivar: 0.3` is not a valid variable. >>
I need some help. How should I be constructing this function to work with vectors? Is there a more natural way in Mathematica to accomplish this?