Computing Divergence of a vector field numerically

3 Ansichten (letzte 30 Tage)
SDSW_6207
SDSW_6207 am 17 Okt. 2017
Bearbeitet: John Kelly am 24 Aug. 2018
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

Antworten (1)

John D'Errico
John D'Errico am 17 Okt. 2017
Bearbeitet: John Kelly am 24 Aug. 2018
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
.

Kategorien

Mehr zu Mathematics finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by