Mathematica 9 is now available
Student Support Forum
Student Support Forum: 'making a function from imported data' topicStudent Support Forum > General > "making a function from imported data"

Next Comment >Help | Reply To Topic
Author Comment/Response
09/22/09 7:22pm

Suppose I have a file called "test" that contains some text, like


or more generally


I want to import the file, and use the contents to define a new function (or vector function) with t as the variable. (I want a big list of names for functions in a system of ODEs.)

I've tried using Import, ReadList, and Get, but these don't seem to work. For example,

In[1]:= f[t_]:=Get["test"]
In[2]:= f[t]
Out[2]:= g[t]

which initially looks right, but...

In[3]:= f[7]
Out[3]:= g[t]

It is as though the function f is the constant function whose value is the string "g[t]". The same thing happens with Import and ReadList. Of course, if I just things in manually

In[4]:= f[t_]:=g[t]

then things work out as desired:

In[5]:= f[t]
Out[5]:= g[t]
In[6]:= f[7]
Out[6]:= g[7]

I want to import the names from a file so that I can automate an otherwise very long and tedious process. What is the issue here, and how might I resolve it?

URL: ,

Subject (listing for 'making a function from imported data')
Author Date Posted
making a function from imported data mike 09/22/09 7:22pm
Re: making a function from imported data yehuda ben-s... 09/24/09 02:10am
Next Comment >Help | Reply To Topic