Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Import polynomial from file and define function from it.

4 views
Skip to first unread message

nick_twisp

unread,
Sep 1, 2010, 6:27:06 AM9/1/10
to
Hello Mathematica community,

I am looking for a solution of the following problem:

I have some quite long polynomial in q and x stored in a file and
with

test = Import["this_file_containing_the_polynomial"];

I import the string and with

poly = ToExpression[test];

I convert it to an expression. If I usually would like to define a
function (like in this case in x and q) from it, I would write

F[q_, x_] := poly;

Unfortunately this doesn't work at all. Strange enough if I just paste
the huge expression behind F[q_, x_]:=, then it works and I have a
function in q and x, which is evaluated when I put a concrete number
e.g. for q (then becoming a polynomial in x).

Does someone have an idea, how I could define a function from an
expression?

Thanks in advance,


E. Pérez Herrero

unread,
Sep 2, 2010, 2:30:44 AM9/2/10
to
Example:


(* Exporting the formula *)
Export["test.txt", "F[x_,y_]:=3*x^2+x*y+3"]

(* Importing data *)
ToExpression[Import["test.txt"]]

Now you can use F:

F[2,3]

21

0 new messages