0
$\begingroup$

I use Mathematica to calculate many analytic expressions, some of them are generated by a loop process, the result can be a vector with a index, e.g., f[i].

Now I want to save them in a file, for example Mathematica package file "result.m", and other expression may also want to be added into this file. The file should looks like this:

f[1] = ;
f[2] = ;
...
f[10] = ;

fsum = ;
gxyz = ;

This should be a simple task, but I can't figure out the solution. Does anyone know how it can be done?

$\endgroup$
0
$\begingroup$

You can use Save:

Save["test.m", {f, fsum, gxyz}]

For instance:

Table[f[i] = i^2, {i, 10}];
fsum = 385;
gxyz = "blabla";

Save["test.m", {f, fsum, gxyz}];

FilePrint["test.m"]

f[1] = 1

f[2] = 4

f[3] = 9

f[4] = 16

f[5] = 25

f[6] = 36

f[7] = 49

f[8] = 64

f[9] = 81

f[10] = 100

fsum = 385

gxyz = "blabla"

$\endgroup$
  • $\begingroup$ Thanks a lot! That's simple and works well! $\endgroup$ – Traceless Jul 20 '14 at 18:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.