Mathematica Mathematica 5 - Loading a Package

  • Thread starter Thread starter DivGradCurl
  • Start date Start date
  • Tags Tags
    Mathematica
AI Thread Summary
A user experienced issues with reloading a package in Mathematica to plot a direction field of a differential equation. After successfully using the package previously, the command returned the input instead of a plot upon re-execution. The user noted that reloading the package with the command <<Graphics`PlotField` did not resolve the issue. Suggestions included using the "Needs" command to load the package only if it hasn't been loaded already, which prevents reloading issues. Additionally, utilizing "Clear" and "Remove" functions can help reset user-defined functions that may cause similar problems when evaluated multiple times. The discussion highlighted the importance of managing package loading and function states in Mathematica to avoid such complications.
DivGradCurl
Messages
364
Reaction score
0
Yesterday, I loaded a package so that I could plot a direction field of a differential equation. It worked just fine. The problem is that now that I want to do it again, it won't work! Using the same Mathematica Notebook, I tried the following:

1. LOAD THE PACKAGE AGAIN

<<Graphics`PlotField`

2. ENTER THE COMMAND AGAIN

PlotVectorField[{1, 9.8-v/5}, {t, 0, 10}, {v, 40, 60}, ScaleFunction->(1&), Axes->True, AspectRatio->1, AxesLabel->{"t", "v"}]

As soon as I enter the command, the output is not a plot, it is the command itself! I also checked out the help section, but I couldn't find anything for this particular problem.

Any help is highly appreciated.
 
Physics news on Phys.org
I've noticed something similar on a couple of occations and haven't really figured how to get over it ... the "solution" I've adopted is to write the line again after completely deleting it, which is a really solution (or shutting down kernel etc.). Have been able to repeat the problem with some packages, don't know whether it has something to do with "row history" or something like that, as bizarre as it sounds ...
 
Why would you want to load the same package more than once?

- Warren
 
Well, I tried to reload it since I closed Mathematica and its notebook yesterday. Now I see what you mean. Next time, I just shouldn't worry and redo things (the package remains loaded if I keep a copy of the notebook)! Thank you guys.
 
Look up "needs" command in help. This will only load the package if it has not already been loaded.

Alternatively if the problem has already happened you can use the "clear" and "remove" functions to remove the function. Then when you load the package again the function will be reloaded as well.

On a side note...
Same sort of problem can happen if you evaluate a user defined function multiple times.
Using "clear" and/or "remove" works in this case too.
 
Davorak said:
On a side note...
Same sort of problem can happen if you evaluate a user defined function multiple times.
Using "clear" and/or "remove" works in this case too.

Went through a script which was giving trouble and this was actually it, hadn't been careful with Clear etc. basic specs ... :smile:
 
Last edited:

Similar threads

Replies
2
Views
2K
Replies
4
Views
3K
Replies
3
Views
2K
Replies
1
Views
5K
Replies
1
Views
3K
Back
Top