Reputation: 33
I'm just getting started on Mathematica and trying to define a function for later use. The function is:
test[x_]:=x^2
While I don't close Mathematica, I can use the function on my notebooks but when I close it, the function disappears, I tried to save a .m
file with it but It didn't work. What do I do?
Upvotes: 2
Views: 2377
Reputation: 5248
Open Mathematica, create a new Notebook
test[x_]=x^2;
DumpSave["test.mx",test];
You even don't have to save the Notebook, just close Mathematica.(But remember, in this case, you lose chance to modify the function forever) Then reopen Mathematica, create a new Notebook
DumpGet["test.mx"];
test[5]
(*25*)
Upvotes: 1
Reputation: 16812
Maybe you misunderstand how to save/import. Here's the process that should work:
test.m
(In Mathematica 8, it won't "look like" you saved it, the open notebook is still "Untitled-1", but it did save. You can verify however you like.)Import["C:\\users\\joeblow\\documents\\Mathematica Notebooks\\test.m"]
test
functionDoes this not work for you?
Upvotes: 4