Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
|
|
Can't read a package
Posted:
Nov 26, 2010 5:29 AM
|
|
I am very frustrated that, after a year with Mathematica, I still cannot create and use packages. I must be missing something elementary.
Here is what I have attempted. I think there is just one missing part:
Step 1: "write" a package: In the tutorial "Setting Up Mathematica Packages" there is source for the sample package "Collatz.m". I copied that source and pasted it into a new Mathematica file, then used the "Save As" command to save the file as a package, naming it "collatz.m" and placing it in a folder called packages.
Step 2: Try to use the package: 1. I create a new Mathematica notebook file, put the following five lines in it, and save it as "collatz.nb" alongside "collatz.m":
SetDirectory["~/desktop/MathNoteBooks/packages"]; FileNames[] PrependTo[$Path, Directory[]] (* missing step; neither << collatz.m nor Import["collatz.m"] works *) Collatz[5] (* 'Collatz' remains undefined *)
Missing Step: Executing the above code, the output from "FileNames" shows that both files exist in the directory. So what code should replace the fourth line above? Or have I gone astray elsewhere?
|
|
|
|