Computing Divergence of a vector field numerically

조회 수: 3 (최근 30일)
SDSW_6207
SDSW_6207 2017년 10월 17일
편집: John Kelly 2018년 8월 24일
I am trying to compute the divergence at individual points of a vector field numerically. I have had issues with Matlab returning nonzero arrays when it should return all zero's. For example:
[x y] = meshgrid(0:pi/2:2*pi,0:pi/2:2*pi); u = sin(x); v = -y*cos(x); divergence(x,y,u,v)
The divergence of this field evaluates symbolically to 0, so why am I not getting this result numerically?
Thank you

답변 (1개)

John D'Errico
John D'Errico 2017년 10월 17일
편집: John Kelly 2018년 8월 24일
First, divergence computes a NUMERICAL approximation to the gradients necessary. It has no clue as to the real derivatives, or the real functions that created these variables. With such a coarse grid, you would never expect a true zero result, even if 0 is the correct result in symbolic terms.
Having said that, you need to understand the * and .* operators in MATLAB.
  • is used for MATRIX multiplication.
.* is used for element-wise multiplication.
There IS a difference.
So, if we use a rather finer grid, and use the proper operator where necessary, you might see something more reasonable.
[x y] = meshgrid(linspace(0,2*pi,100)); u = sin(x); v = -y.*cos(x); divergence(x,y,u,v)
.
doc mtimes
doc times
.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by