Calculate derivatives in a non-uniform grid
43 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponses (3)
Star Strider
le 1 Août 2019
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 commentaires
Star Strider
le 1 Août 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
le 22 Juin 2020
[dux, duy] = gradient(U, x, y);
duy ./ dux
perhaps?
Alessandro Mura
le 22 Juin 2020
Modifié(e) : Alessandro Mura
le 22 Juin 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;
0 commentaires
Justino Martinez
le 15 Jan 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?
0 commentaires
Voir également
Catégories
En savoir plus sur Polynomials dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!