I have experimental data containing horizontal and vertical components of speed and I need to evaluate this:

$$ \frac{\partial^2}{\partial x_i \partial x_j}\left(v_iv_j\right) $$

Denoting $U$ as horizontal component and $V$ as vertical, we should obtain:

$$ \frac{\partial^2}{\partial x_i \partial x_j}\left(v_iv_j\right) \rightarrow \frac{\partial^2}{\partial x^2}(U^2)+\frac{\partial^2}{\partial y^2}(V^2) + 2\frac{\partial^2}{\partial x \partial y}(UV) $$

I have used central finite difference of the second order for $\partial^2/\partial x^2$ and finite difference of the first order for mixed derivative. In MATLAB:

%H and WW are height and width respectively
for ii=3:H-2
    for jj=3:WW-2



        %Mixed derivative

        %sum of derivatives


Results are not very satisfactory so far: "wild unconnectivity" all around the screen.

  • Do I have a mistake somewhere?
  • Would you use different kind of scheme?
  • What kind of data treatment (spline?) would you recommend for obtaining smoother results?

Example of input data:

Example of input data


Output data

  • $\begingroup$ Welcome to SciComp.SE! Could you add more detail (ideally, with some pictures) about what kind of data you have, what you expect to see, and what you are seeing ("wild unconnectivity" is a bit vague...) $\endgroup$ Sep 30 '15 at 10:03
  • $\begingroup$ OK, I will try to elaborate something 'visible' (quiver plot 100x200 is not readible in this site). I haven't post anything specific cause I expect a mistake somewhere in process. $\endgroup$ Sep 30 '15 at 10:07
  • $\begingroup$ (If it's just applying the product rule, then it's wrong -- you should always get products of derivatives, not derivatives of products, otherwise there'd be no point...) $\endgroup$ Sep 30 '15 at 10:44
  • $\begingroup$ That might be the mistake. Could you please be a bit more specific? $\endgroup$ Sep 30 '15 at 10:46

Your reformulation is wrong: The product rule for derivatives is $(uv)' = u'v + uv'$. Applying this in your situation (with $\partial_x$ instead of $\frac{\partial}{\partial x}$ and $\partial_{xy} = \frac{\partial^2}{\partial x\partial y}$ for brevity would yield $$\partial_{xy}(uv) = \partial_y(\partial_x u \,v + u\,\partial_x v) = \partial_{xy}u \,v + \partial_x u \, \partial_y v + \partial_y u\,\partial_x v + u\,\partial_{xy}v $$ (note that you have four different terms, not three).

If you want to have a second-order accurate scheme (mixing schemes of different accuracy is in general a waste of effort), the standard stencils are

$$\partial_x u_{ij} \approx \frac{u_{i+1,j}-u_{i-1,j}}{2h},\qquad\partial_y u_{ij} \approx \frac{u_{i,j+1}-u_{i,j-1}}{2h}$$ and $$\partial_{xy} u_{ij} \approx \frac{u_{i+1,j+1}-u_{i+1,j-1}-u_{i-1,j+1}+u_{i-1,j-1}}{4h^2}.$$ You can either apply the second directly to $(u\,v)_{ij}$, or plug in both stencils on the right-hand side. (Or better yet, both, and compare the results.)

  • $\begingroup$ Embarassingly stupid of me... Thanks a lot! That probably will be the issue. I'll try that. If you would be so kind and recommend the finite difference scheme, I'll be grateful. $\endgroup$ Sep 30 '15 at 11:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.