Suppose that I have a function $f:[0,1]^2 \to \mathbb{R}$ and I would like to approximate it from its values in the corners of the domain by the well-known formula $$ f(s,t) \approx (1-s,s) \begin{pmatrix} f(0,0) & f(0,1) \\ f(1,0) & f(1,1) \end{pmatrix} \begin{pmatrix} 1-t\\ t \end{pmatrix} \enspace, $$ which can be found on Wikipedia.
I tried two ways of writing this in Mathematica:
bilinearExpl[f_, s_, t_] :=
(1 - s) (1 - t) f[0, 0] + (1 - s) t f[0, 1] + (1 - t) s f[1, 0] + s t f[1, 1]
bilinearMatr[f_, s_, t_] := {1 - s, s}.{{f[0, 0], f[0, 1]}, {f[1, 0], f[1, 1]}}.{1 - t, t}
If I try them out, they produce results that are quite much the same:
bilinearExpl[f, s, t]
gives
whereas
bilinearMatr[f, s, t]
returns
Taking a function
scalarFunction[x_, y_] := x^2 y
as an example, they also produce the same approximation of scalarFunction
.
{Plot3D[scalarFunction[s, t], {s, 0, 1}, {t, 0, 1}, Mesh -> {11, 11}],
Plot3D[bilinearExpl[scalarFunction, s, t], {s, 0, 1}, {t, 0, 1}, Mesh -> {11, 11}],
Plot3D[bilinearMatr[scalarFunction, s, t], {s, 0, 1}, {t, 0, 1}, Mesh -> {11, 11}]}
So far so good. The same formula should work for a function $f:[0,1]^2 \to \mathbb{R}^2$ and both methods should give the same results. But they don't! Take, for instance,
vectorFunction[x_, y_] := {x, y}
Then
{ParametricPlot[vectorFunction[s, t], {s, 0, 1}, {t, 0, 1}, Mesh -> {11, 11}],
ParametricPlot[bilinearExpl[vectorFunction, s, t], {s, 0, 1}, {t, 0, 1}, Mesh -> {11, 11}],
ParametricPlot[bilinearMatr[vectorFunction, s, t], {s, 0, 1}, {t, 0, 1}, Mesh -> {11, 11}]}
gives
and the two right plots are certainly not the same.
Question: why are the results of the two (seemingly equivalent) formulas different?
I suppose there is some dimension mismatch of the arrays.