Borrar filtros
Borrar filtros

Calculate derivatives in a non-uniform grid

58 visualizaciones (últimos 30 días)
moreza7
moreza7 el 1 de Ag. de 2019
Respondida: Justino Martinez el 15 de En. de 2024
I have a non-uniform grid (non-equal intervals between nodes). [x,y]
I also have the data (U) calculated on this grid.
I want to calculate the derivatives of U.
How can I do this?

Respuestas (3)

Star Strider
Star Strider el 1 de Ag. de 2019
The gradient function is an option, specifically:
dydx = gradient(y) ./ gradient(x);
for vectors, or more generally for matrices:
[dxr,dxc] = gradient(x);
[dyr,dyc] = gradient(y);
dc = dyc./dxc; % Column Derivatives
dr = dyr./dxr; % Row Derivatives
Try that to see if it gives you an acceptable result.
  3 comentarios
Star Strider
Star Strider el 1 de Ag. de 2019
I am guessing that your ‘non-uniform grid’ (that I call ‘G’ here) is a matrix, as is ‘U’.
I would do something like this:
[dxr,dxc] = gradient(G);
[dyr,dyc] = gradient(U);
dc = dyc./dxc; % Column Derivatives
dr = dyr./dxr; % Row Derivatives
So ‘dc’ takes the derivatives along the columns, and ‘dr’ along the rows. See the documentation for the gradient function (that I linked to in my Answer) for details.
Walter Roberson
Walter Roberson el 22 de Jun. de 2020
[dux, duy] = gradient(U, x, y);
duy ./ dux
perhaps?

Iniciar sesión para comentar.


Alessandro Mura
Alessandro Mura el 22 de Jun. de 2020
Editada: Alessandro Mura el 22 de Jun. de 2020
Hi,
the solution is using the Jacobian matrix.
This is used to transform gradients between the coordinate system of (row,column) to (x,y).
First calculate the gradients of U,x and y
[dxi,dxj]=gradient(x);
[dyi,dyj]=gradient(y);
[dui,duj]=gradient(u);
then the Jacobian of the transformation is
[dxi dxj
dyi dyj]
the determinant is
DET=dxi.*dyj- dxj.*dyi;
the inverse of the Jacobian has these 4 coefficients:
JAC11=DET.*dxi;
JAC21=DET.*dyi;
JAC12=DET.*dxj;
JAC22=DET.*dyj;
Then to transform the gradient [dui,duj] into dux, duy you just do:
dux=dui.*JAC11+duj.*JAC12;
duy=dui.*JAC21+duj.*JAC22;

Justino Martinez
Justino Martinez el 15 de En. de 2024
I don't know if I have missing something in the notation, but the inverse of the Jacobian for these 4 coefficients shold be
JAC11 = dyj./DET
JAC21 = -dxj./DET
JAC12 = -dyi./DET
JAC22 = dxi./DET
isn't it?

Categorías

Más información sobre Logical en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by