1
$\begingroup$

I can find solutions of linear equations like below:

sol = Flatten[  Solve[{2 Subscript[C, 1] + 2 Subscript[C, 2] == -1, 
     2 Subscript[C, 1] + 3 Subscript[C, 2] == 1}]] 
Export["sol.csv", sol, "CSV"]
sol = Import["sol.csv", "CSV"]

How can i export and import solution in Mathematica with appearing function subscript in list.(when i import solution function of subscript appear in my solution).

$\endgroup$
1
  • 1
    $\begingroup$ How are you currently exporting and importing. Please edit your post and provide the code. $\endgroup$
    – Edmund
    Commented Jun 28, 2017 at 20:49

2 Answers 2

2
$\begingroup$

CSV (Comma-separated values) uses comma as delimiter and, hence, interpreting the comma in Subscript[C, 1] as a field separator, exports Subscript[C, 1] -> -5/2 as {"Subscript[C", " 1] -> -5/2"}

sol = Flatten[Solve[{2 Subscript[C, 1] + 2 Subscript[C, 2] == -1, 
    2 Subscript[C, 1] + 3 Subscript[C, 2] == 1}]]
Export["sol.csv", sol, "CSV"];
imported = Import["sol.csv", "CSV"]

{{"Subscript[C", " 1] -> -5/2"}, {"Subscript[C", " 2] -> 2"}}

this can be seen in the file sol.csv Mathematica graphics

You can use import it as TSV (Tab-separated values) instead to avoid this issue:

imported2 = Import["sol.csv", "TSV"]

{{"Subscript[C, 1] -> -5/2"}, {"Subscript[C, 2] -> 2"}}

ToExpression@imported2

Mathematica graphics

$\endgroup$
1
$\begingroup$

Using

sol // ToString // ToExpression // TableForm // TraditionalForm

will give you

$C_1 \rightarrow -\frac{5}{2}$

$C_2 \rightarrow 2$.

ToString converts it to a string. ToExpression is the most important one, converting it to a mathematical expression. TableForm and TraditionalForm will make it pretty. I think you are exporting as .csv and that's why the imported format is not usable. Instead, you can use .dat or .txt.

$\endgroup$
3
  • $\begingroup$ It doesn't work if we have two or three or more subscripts $\endgroup$
    – Farid
    Commented Jun 28, 2017 at 22:05
  • $\begingroup$ @Farid, Did you save it as .dat? Or you are insisting on using .csv? Provide an example, please. $\endgroup$
    – Miladiouss
    Commented Jun 28, 2017 at 22:26
  • $\begingroup$ I save it in dat form and arise same problem $\endgroup$
    – Farid
    Commented Jun 28, 2017 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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