Skip to main content
replaced http://mathematica.stackexchange.com/ with https://mathematica.stackexchange.com/
Source Link

Using jVincent's ContextScope[]jVincent's ContextScope[]

m`str1 = "y = 0.97*x1 + 0.521*x2 - 30.21 - 0.07431*x3 - 0.126*x4 - 0.1939*x5 - 0.361*x6";
ContextScope["m`", {SymbolName /@ Variables@#, 
                    Coefficient[#, Variables@#]} &@ToExpression[str1] // Transpose]
(*
{{"x1", 0.97`}, {"x2", 0.521`}, {"x3", -0.07431`}, 
 {"x4", -0.126`}, {"x5", -0.1939`}, {"x6", -0.361`}}
*)

Using jVincent's ContextScope[]

m`str1 = "y = 0.97*x1 + 0.521*x2 - 30.21 - 0.07431*x3 - 0.126*x4 - 0.1939*x5 - 0.361*x6";
ContextScope["m`", {SymbolName /@ Variables@#, 
                    Coefficient[#, Variables@#]} &@ToExpression[str1] // Transpose]
(*
{{"x1", 0.97`}, {"x2", 0.521`}, {"x3", -0.07431`}, 
 {"x4", -0.126`}, {"x5", -0.1939`}, {"x6", -0.361`}}
*)

Using jVincent's ContextScope[]

m`str1 = "y = 0.97*x1 + 0.521*x2 - 30.21 - 0.07431*x3 - 0.126*x4 - 0.1939*x5 - 0.361*x6";
ContextScope["m`", {SymbolName /@ Variables@#, 
                    Coefficient[#, Variables@#]} &@ToExpression[str1] // Transpose]
(*
{{"x1", 0.97`}, {"x2", 0.521`}, {"x3", -0.07431`}, 
 {"x4", -0.126`}, {"x5", -0.1939`}, {"x6", -0.361`}}
*)
deleted 13 characters in body
Source Link
Dr. belisarius
  • 116.2k
  • 13
  • 205
  • 456

Using jVincent's ContextScope[]

m`str1 = "y = 0.97*x1 + 0.521*x2 - 30.21 - 0.07431*x3 - 0.126*x4 - 0.1939*x5 - 0.361*x6";
ContextScope["m`", {InputForm /@ SymbolName /@ Variables@#, 
                    Coefficient[#, Variables@#]} &@ToExpression[str1] // Transpose]
(*
{{"x1", 0.97`}, {"x2", 0.521`}, {"x3", -0.07431`}, 
 {"x4", -0.126`}, {"x5", -0.1939`}, {"x6", -0.361`}}
*)

Using jVincent's ContextScope[]

m`str1 = "y = 0.97*x1 + 0.521*x2 - 30.21 - 0.07431*x3 - 0.126*x4 - 0.1939*x5 - 0.361*x6";
ContextScope["m`", {InputForm /@ SymbolName /@ Variables@#, 
                    Coefficient[#, Variables@#]} &@ToExpression[str1] // Transpose]
(*
{{"x1", 0.97`}, {"x2", 0.521`}, {"x3", -0.07431`}, 
 {"x4", -0.126`}, {"x5", -0.1939`}, {"x6", -0.361`}}
*)

Using jVincent's ContextScope[]

m`str1 = "y = 0.97*x1 + 0.521*x2 - 30.21 - 0.07431*x3 - 0.126*x4 - 0.1939*x5 - 0.361*x6";
ContextScope["m`", {SymbolName /@ Variables@#, 
                    Coefficient[#, Variables@#]} &@ToExpression[str1] // Transpose]
(*
{{"x1", 0.97`}, {"x2", 0.521`}, {"x3", -0.07431`}, 
 {"x4", -0.126`}, {"x5", -0.1939`}, {"x6", -0.361`}}
*)
Source Link
Dr. belisarius
  • 116.2k
  • 13
  • 205
  • 456

Using jVincent's ContextScope[]

m`str1 = "y = 0.97*x1 + 0.521*x2 - 30.21 - 0.07431*x3 - 0.126*x4 - 0.1939*x5 - 0.361*x6";
ContextScope["m`", {InputForm /@ SymbolName /@ Variables@#, 
                    Coefficient[#, Variables@#]} &@ToExpression[str1] // Transpose]
(*
{{"x1", 0.97`}, {"x2", 0.521`}, {"x3", -0.07431`}, 
 {"x4", -0.126`}, {"x5", -0.1939`}, {"x6", -0.361`}}
*)