Mathematica Mathematica: Div in Cylindrical and Shadowing

AI Thread Summary
The discussion revolves around an issue with calculating the divergence of a vector in cylindrical coordinates using Mathematica, where the expected result of zero is not returned. The user encounters a "shadowing" warning related to the Div operator, indicating that a custom definition may be overriding the built-in function. It is suggested that the VectorAnalysis package may have redefined Div, which could explain the unexpected output. To resolve the issue, users are advised to simplify their results and consider unprotecting the Div function if necessary, but with caution regarding potential consequences. The conversation emphasizes the importance of understanding how contexts and definitions interact in Mathematica.
Saladsamurai
Messages
3,009
Reaction score
7
Mathematica: Div in Cylindrical and "Shadowing"

I have a vector given in cylindrical coordinates. I know that the divergence of the vector should be zero. However, I am not sure why Mathematica is not returning zero. Also, the Div operator is showing up red (Div) and it is saying something about Shadowing. I have no idea what this means and the help is a little cryptic about it. I tried using Remove[Div] but it is protected. I am not sure what to do about that. This is the code i am using:

Code:
Clear["Global`*"]
Needs["VectorAnalysis`"]
Vr = (A/r^2 - B) Cos[theta];
Vtheta = (A/r^2 + B) Sin[theta];
Div[{Vr, Vtheta, 0}, Cylindrical[r, theta, z]]

which should give zero, but instead it gives me an algebraic expression.
 
Physics news on Phys.org


For your red Div and warning search in this

http://reference.wolfram.com/mathematica/tutorial/Contexts.html

for red and read the explanation. Somehow you or perhaps VectorAnalysis has introduced a definition of Div that is going to be used before the built-in definition of Div and Mathematica is warning you about that.

Why your divergence isn't zero I haven't pursued.
 


For your red Div and warning search in this

http://reference.wolfram.com/mathematica/tutorial/Contexts.html

for red and read the explanation. Somehow you or perhaps VectorAnalysis has introduced a definition of Div that is going to be used before the built-in definition of Div and Mathematica is warning you about that.

Why your divergence isn't zero I haven't pursued.

Sorry, must have clicked twice, so edit this to add some additional information.

It isn't necessarily a bad thing that Div was redefined. VectorAnalysis may have broadened the definition or added new abilities. The reason for the warning when you tried to Remove[Div] is that for your safety most internal features have write/delete protection. If you really want to Remove[Div] you would have to Unprotect it first, but I would make certain that you know you need to do that and you understand the consequences. If VectorAnalysis did redefine Div then what it did was Unprotect, change the definition and then Protect it again.
 
Last edited:


Saladsamurai said:
I have a vector given in cylindrical coordinates. I know that the divergence of the vector should be zero. However, I am not sure why Mathematica is not returning zero. Also, the Div operator is showing up red (Div) and it is saying something about Shadowing. I have no idea what this means and the help is a little cryptic about it. I tried using Remove[Div] but it is protected. I am not sure what to do about that. This is the code i am using:

Code:
Clear["Global`*"]
Needs["VectorAnalysis`"]
Vr = (A/r^2 - B) Cos[theta];
Vtheta = (A/r^2 + B) Sin[theta];
Div[{Vr, Vtheta, 0}, Cylindrical[r, theta, z]]

which should give zero, but instead it gives me an algebraic expression.

Have you tried to simplify the result? Here's what I obtain in Mathematica 6:

Code:
In[1]:= Vr = (A/r^2 - B) Cos[theta];
Vtheta = (A/r^2 + B) Sin[theta];
divV = 1/r D[r Vr, r] + 1/r D[Vtheta, theta] // Simplify

Out[3]= 0

In[4]:= Needs["VectorAnalysis`"]
Div[{Vr, Vtheta, 0}, Cylindrical[r, theta, z]]

Out[5]= ((-B + A/r^2) Cos[theta] + (B + A/r^2) Cos[theta] - (
 2 A Cos[theta])/r^2)/r

In[6]:= % // Simplify

Out[6]= 0
 

Similar threads

Replies
1
Views
2K
Replies
2
Views
6K
Replies
6
Views
2K
Replies
1
Views
2K
Back
Top