Calculate derivatives in a non-uniform grid

43 Ansichten (letzte 30 Tage)
moreza7
moreza7 am 1 Aug. 2019
Beantwortet: Justino Martinez am 15 Jan. 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?

Antworten (3)

Star Strider
Star Strider am 1 Aug. 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 Kommentare
Star Strider
Star Strider am 1 Aug. 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 am 22 Jun. 2020
[dux, duy] = gradient(U, x, y);
duy ./ dux
perhaps?

Melden Sie sich an, um zu kommentieren.


Alessandro Mura
Alessandro Mura am 22 Jun. 2020
Bearbeitet: Alessandro Mura am 22 Jun. 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 am 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?

Kategorien

Mehr zu Polynomials finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by