0
$\begingroup$

If I have an equation in Mathematica, say

f=a*x+Exp[x]

is it possible to save only RHS of the equation into a text or mx file, so that later I can load it and assign it to some other variable? Save seems to save the whole thing. Thanks for any help in advance.

$\endgroup$
  • $\begingroup$ Try Put and friends $\endgroup$ – Kuba Nov 24 '16 at 11:28
  • $\begingroup$ That's not an equation, an equation is of the form f == a*x + Exp[x]. If you store this equation in g with g = f == a*x + Exp[x], running g[[2]] returns the RHS of the equation. $\endgroup$ – Feyre Nov 24 '16 at 12:09
2
$\begingroup$

Your expression

f = a*x + Exp[x]

is an assignment to the variable f, not an equation. If you save f to a file, you will be saving its value, which is exactly what you want.

Suppose you want the save the file to your desktop, then you could write

f = a*x + Exp[x]

E^x+a x

path = FileNameJoin[{$HomeDirectory, "Desktop", "f.m"}];
Put[f, path]

and retrieve it with

Get[path]

E^x+a x

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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