3

I want to make a script for solving liniar equations (in Mathematica) with something like:

Solve[{InputString["Solving Linear Equations"]}]

The output is similar to:

Solve[{"x+y+z==0,x+y+z==0,x+y+z==0"}]

I want to remove the quotation marks. Is there a way to do this?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257

2 Answers2

2

Just for fun, here is a way to do it with AskFunction.

solver =
  AskFunction[
    Solve[Ask["equations" -> "Expression"], Ask["variables" -> "Expression"]]];

solver[]

input1

input2

{{x -> 2/3, y -> 1/3}}

Note: This has the advantage that you don't have to convert strings to expressions and the disadvantage requiring an internet connection to convert the textual inputs into Mathematica expressions.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
0
Solve[ToExpression@
  StringSplit[InputString["Solving Linear Equations"], ","]]

Paste in x+y+z==0,x+y+z==0,x+y+z==0

{{z -> -x - y}}

Chris Degnen
  • 30,927
  • 2
  • 54
  • 108
  • Always be wary of using ToExpression blindly. For your code, a user could enter something like Print["deleting files"], DeleteFile /@ FileNames["*"] at the prompt. – Jason B. Nov 16 '17 at 17:33