- is used for MATRIX multiplication.
Computing Divergence of a vector field numerically
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (1)
John D'Errico
el 17 de Oct. de 2017
Editada: John Kelly
el 24 de Ag. de 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 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
.
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!