Computing Divergence of a vector field numerically

3 vues (au cours des 30 derniers jours)
SDSW_6207
SDSW_6207 le 17 Oct 2017
Modifié(e) : John Kelly le 24 Août 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

Réponses (1)

John D'Errico
John D'Errico le 17 Oct 2017
Modifié(e) : John Kelly le 24 Août 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
.

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by