필터 지우기
필터 지우기

Calculate derivatives in a non-uniform grid

조회 수: 58 (최근 30일)
moreza7
moreza7 2019년 8월 1일
답변: Justino Martinez 2024년 1월 15일
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?

답변 (3개)

Star Strider
Star Strider 2019년 8월 1일
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
Star Strider
Star Strider 2019년 8월 1일
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 2020년 6월 22일
[dux, duy] = gradient(U, x, y);
duy ./ dux
perhaps?

댓글을 달려면 로그인하십시오.


Alessandro Mura
Alessandro Mura 2020년 6월 22일
편집: Alessandro Mura 2020년 6월 22일
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 2024년 1월 15일
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?

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by