0
|
4722 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
GROUPS:

# Way to import formulas in a textfile in Wolfram Mathematica

Posted 11 years ago
 Hi,Is there a way to import formulas in a textfile into Wolfram Mathematica?I have a text file that has in every line a formula to calculate.  So is there a way to import. ala .csv file or so?Example for this text file:453645 + 567323 =3453454 + (3453454 * 5756757) =....
3 Replies
Sort By:
Posted 11 years ago
 In[1]:= strings = Import["formula.txt"];f[s_] := s <> "=" <> ToString[ToExpression[s]];TableForm[Map[f, StringDrop[StringSplit[strings, "=\n"], -1]]]Out[3]= 453645 + 567323=10209683453454 + (3453454 * 5756757) =19880698942132
Posted 11 years ago
 Dear Sir,Thank you for your answer.Yes, this works.Second: Is there a way to write the formula left on the sum too? Is there a way to make a new line when there is a new sum?ex. Out[3]= {453645 + 567323 = 10209683453454 + (3453454 * 5756757) = 19880698942132.......}
Posted 11 years ago
 In[1]:= strings = Import["formula.txt"];ToExpression[StringDrop[StringSplit[strings, "=\n"], -1]]Out[2]= {1020968, 19880698942132}where formula.txt contains the two lines you showed in your example. You may need to provide a path to your text file, depending on location.This can also beIn[3]:= ToExpression[StringDrop[StringSplit[Import["formula.txt"], "=\n"], -1]]Out[3]= {1020968, 19880698942132}
Community posts can be styled and formatted using the Markdown syntax.