Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
A stupid question about divergence and curl

Subject: A stupid question about divergence and curl

From: Andrew

Date: 2 Apr, 2009 04:52:01

Message: 1 of 3

The documentation about divergence and curl is unclear (to me) about what values, and even functions, these operations are evaluated at. For example when I use this code:

x=-3:.1:3;y=-3:.1:3;
z=exp(-(x.^2+y.^2));
[X Y]=meshgrid(x.*z,y.*z);
[U V]=randn(61,61);
div=divergence[X,Y,U,V]

I get a set of values for the variable "div" that I assume is the divergence of something, but I can't tell what. Then, I change the values of U and V to:

[U V]=meshgrid(x,y);
div=divergence[X,Y,U,V]

I get a different set of values. However, neither of these evaluates the divergence of the vector function [X Y] at the point indicated in [U V]. Is not this what this command is supposed to do? Does anybody know the proper syntax?

Thank You for Responding:

Andrew Stallard

Subject: A stupid question about divergence and curl

From: Bruno Luong

Date: 2 Apr, 2009 07:01:03

Message: 2 of 3

"Andrew" <joeblow@aol.com> wrote in message <gr1g9h$hba$1@fred.mathworks.com>...
> The documentation about divergence and curl is unclear (to me) about what values, and even functions, these operations are evaluated at. For example when I use this code:
>
> x=-3:.1:3;y=-3:.1:3;
> z=exp(-(x.^2+y.^2));
> [X Y]=meshgrid(x.*z,y.*z);
> [U V]=randn(61,61);
> div=divergence[X,Y,U,V]

Why you deform the grid [X,Y] with a non monotonic function ? (X,Y) are the location where the vector field is defined, you are not allowed to deform them with arbitrary function (sorry in fact you could but then it's not surprising the divergence is garbage)

divergence computes dU/dX+dV/dY using GRADIENT (finite difference method). You can even see the source code.

Bruno

Subject: A stupid question about divergence and curl

From: Roger Stafford

Date: 2 Apr, 2009 07:10:18

Message: 3 of 3

"Andrew" <joeblow@aol.com> wrote in message <gr1g9h$hba$1@fred.mathworks.com>...
> The documentation about divergence and curl is unclear (to me) about what values, and even functions, these operations are evaluated at. For example when I use this code:
>
> x=-3:.1:3;y=-3:.1:3;
> z=exp(-(x.^2+y.^2));
> [X Y]=meshgrid(x.*z,y.*z);
> [U V]=randn(61,61);
> div=divergence[X,Y,U,V]
>
> I get a set of values for the variable "div" that I assume is the divergence of something, but I can't tell what. Then, I change the values of U and V to:
>
> [U V]=meshgrid(x,y);
> div=divergence[X,Y,U,V]
>
> I get a different set of values. However, neither of these evaluates the divergence of the vector function [X Y] at the point indicated in [U V]. Is not this what this command is supposed to do? Does anybody know the proper syntax?
>
> Thank You for Responding:
>
> Andrew Stallard

  I would suggest a thorough rereading of the 'divergence' function documentation, as well as that of 'randn'. You seem to have misinterpreted them rather badly.

 1. Your U, V function matrices are wildly discontinuous if they come from 'randn' and partial derivatives of them would be meaningless.
 2. My guess is you expected 'randn' to give you a smooth two-dimensional bell-shaped surface. It does no such thing.
 3. The syntax of "[U V]=randn(61,61);" is wrong and should give errors.
 4. You are possibly confusing the field values for the dependent variables in your second example. X & Y are the points and U & V the field values there.
 5. Your X, Y matrices are not monotonic, contrary to requirements.

Roger Stafford

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us