Mathematica: Div in Cylindrical and Shadowing

In summary, Mathematica may display a red Div operator and give a warning about Shadowing when a definition of Div has been introduced before the built-in definition. This can be resolved by understanding and managing the definitions in the code. The algebraic expression output for the divergence of a vector in cylindrical coordinates can be simplified to zero.
  • #1
Saladsamurai
3,020
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
  • #2


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.
 
  • #3


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:
  • #4


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
 
  • #5
Can you provide any insights on why this may be happening and how to resolve it?

I am familiar with Mathematica and its use for mathematical and scientific computations. In this case, it seems that there may be some conflicting definitions or functions within the Mathematica package that is causing the issue with the Div operator. The "Shadowing" error could be indicating that there are multiple definitions or functions for the Div operator and Mathematica is unsure which one to use.

One potential solution could be to explicitly specify which Div operator you want to use, such as Div[Cylindrical[r, theta, z], {Vr, Vtheta, 0}]. This will ensure that Mathematica uses the correct definition for the Div operator.

Another solution could be to use the Inactivate function to temporarily deactivate the Div operator and then use Activate to reactivate it after your calculations are done.

It is also possible that there may be a bug or error in the VectorAnalysis package itself. In this case, you could try reaching out to the package developers for further assistance.

Overall, it is important to carefully check the definitions and functions being used in your code and to consult with the Mathematica community or package developers for any issues or errors that you may encounter.
 

Related to Mathematica: Div in Cylindrical and Shadowing

1. What is the "Div in Cylindrical" function in Mathematica used for?

The "Div in Cylindrical" function in Mathematica is used to calculate the divergence of a vector field in cylindrical coordinates. It takes in the three components of the vector field (ρ, φ, and z) and returns the divergence as a function of these coordinates.

2. How is the "Shadowing" feature in Mathematica helpful for scientific applications?

The "Shadowing" feature in Mathematica allows for the creation of multiple versions of a function with different definitions. This can be useful in scientific applications as it allows for more flexibility in manipulating and analyzing data, and also allows for different approaches to problem-solving.

3. Can the "Div in Cylindrical" function handle vector fields with varying magnitudes?

Yes, the "Div in Cylindrical" function in Mathematica is designed to handle vector fields with varying magnitudes. It takes into account the change in magnitude of the vector field in different directions and calculates the divergence accordingly.

4. How does the "Shadowing" feature in Mathematica handle conflicts between different versions of a function?

If there is a conflict between different versions of a function created using the "Shadowing" feature in Mathematica, the version with the most specific definition is used. If there is still a conflict, the version that was most recently defined is used.

5. Can the "Div in Cylindrical" function be used for 3D vector fields?

Yes, the "Div in Cylindrical" function in Mathematica can be used for 3D vector fields. It takes in the components of the vector field in cylindrical coordinates (ρ, φ, and z) and calculates the divergence as a function of these coordinates.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
597
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
3K
Replies
5
Views
804
Replies
4
Views
843
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
6K
  • Linear and Abstract Algebra
Replies
6
Views
1K
Replies
3
Views
894
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
Replies
5
Views
987
Back
Top