Clearing variables and functions in Mathematica

Click For Summary
SUMMARY

This discussion addresses issues encountered in Mathematica when calculating magnetic susceptibility, specifically when evaluating a second derivative at zero magnetic field. Users reported receiving a "1/0 complexinfinity" error due to internal function conflicts, particularly when parameter values are altered. The solution involves using the Clear function to reset user-defined functions, which can resolve evaluation errors caused by divergence in specific function parts. The discussion highlights the importance of ensuring functions are analytical at the points of interest to avoid such errors.

PREREQUISITES
  • Familiarity with Mathematica syntax and functions
  • Understanding of derivatives and limits in calculus
  • Knowledge of magnetic susceptibility in physics
  • Experience with debugging mathematical functions in computational software
NEXT STEPS
  • Research the use of Clear and Remove functions in Mathematica
  • Learn about handling singularities and limits in Mathematica
  • Explore the concept of analytical functions and their importance in calculations
  • Investigate error handling and debugging techniques in Mathematica
USEFUL FOR

This discussion is beneficial for physicists, mathematicians, and software developers who utilize Mathematica for complex calculations, particularly those dealing with derivatives and function evaluations in scientific computing.

matoma28
Messages
2
Reaction score
0
Can anyone help on this?

I am calculating the magnetic susceptibility, essentially a second derivative evaluated at zero magnetic field. The problem is that sometimes Mathematica works perfectly, and sometimes it gives me a "1/0 complexinfinity" error message, with no obvious reason. The problem can arise simply by changing the value of a parameter, but once I return to the parameter values for which it worked fine, Mathematica no longer gives me back the results (it still gives me the same error message). I suspect that it might be an internal problem, i.e. perhaps I need to clear my (user-defined) functions some way.

Chi[Δ_, λ_, θ_, β_] = -D[F, {h, 2}] /. {h -> 0}; (* This works fine *)
Chi[0.4, 0.6, 0.2, β_] (* The problem is here; in particular, when I change the value of θ. Last time the problem occurred because I gave θ a value outside the function (so that I could use in other functions too);

Any help will be greatly appreciated!
 
Physics news on Phys.org
Some problems arise in mathematica with evaulation of functions where parts of the function diverge, though overall it may cancel. An example:

Clear[f]
f[x_] = x/(2 - x) + 2/(x - 2)
f[2]
Limit[f[x], x -> 2]

f[2] will give you 1/0 div by zero error, but this function actually goes to -1 at x=2.

Perhaps there is something in your function that diverges at those specific values (at least in part of the equation), but wouldn't overall.
 
Thanks a lot! It turns out that my function was not analytical at the point of interest, that is why Mathematica did not know which (directional) derivative to give me. Thanks for your response.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 9 ·
Replies
9
Views
4K