Mathematica 5 - Loading a Package

  • Context: Mathematica 
  • Thread starter Thread starter DivGradCurl
  • Start date Start date
  • Tags Tags
    Mathematica
Click For Summary

Discussion Overview

The discussion revolves around issues encountered while loading a package in Mathematica to plot a direction field of a differential equation. Participants share their experiences and suggest potential solutions related to package loading and function evaluation.

Discussion Character

  • Technical explanation, Debate/contested, Meta-discussion

Main Points Raised

  • One participant describes a problem where reloading a package does not produce the expected plot output, instead returning the command itself.
  • Another participant mentions a similar experience and suggests deleting and re-entering the command or restarting the kernel as a workaround, speculating it may relate to "row history."
  • A participant questions the necessity of loading the same package multiple times, implying that it may not be needed if the notebook is preserved.
  • One suggestion is to use the "Needs" command, which only loads the package if it hasn't been loaded already, as a potential solution to avoid reloading issues.
  • Another participant advises using "Clear" and "Remove" functions to address problems with user-defined functions that may arise from multiple evaluations.
  • A later reply reiterates the importance of using "Clear" and "Remove" based on personal experience with similar issues in scripts.

Areas of Agreement / Disagreement

Participants express a range of experiences and solutions, but there is no consensus on a single definitive solution to the problem. Multiple approaches are discussed without agreement on which is the best method.

Contextual Notes

Participants mention potential issues related to the state of the Mathematica kernel and the history of commands, which may affect the loading and execution of packages and functions.

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 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 1 ·
Replies
1
Views
3K