# Assign dynamic string in a list to variables in functions

I have 2 lists:

datastr={0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 2., 0., \
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., \
0., 0., 0., 0., 0., 0., 0.};

dataB={548.29, 94.16, -322.15, -573.56, 495.01, 82.28, "eta11", "eta12", \
"eta13", "eta14", 307.53, -394.29, "eta15", 259.65, -245.74, "eta16", \
625.45, 738.91, 809.55, 2173.72, 3018.17, 122.09, 440.24, 340.35, \
"eta17", 740.92, 1317.23, 483.88, 675.24, "eta18", "eta19", "eta110", \
"eta111", "eta112", "eta113", "eta114", "eta115", "eta116", "eta117", \
"eta118", "eta119"}


I then do a summary of the multiple of the 2 lists and have:

etaa = (Total[dataJ*datastr])


I got:

etaa = -0.199 + 2. "eta26"


I want to set the "eta26" as a variables in a function

Funt[T_,eta26_]:=  (-0.199 + 2. "eta26")*T^2 +  "eta26"


The function Funt[T_,eta26_] is fitted to an experimental data set having values of the Funt and T to find value for the eta26.

Could you please suggest me how to extract the "eta26" in a list and set them as a variable in a Function as give above.

Thank and regards,

Anh

• What is the definition of dataJ? Nov 13, 2019 at 5:22
• Dear Rohit Namjoshi, it is a typo mistake. It should be dataB, not dataJ. Thank you
– Anh
Nov 13, 2019 at 8:27

Convert the strings to symbols using ToExpression.

expr = ToExpression@dataB;
etaa = Total[expr*datastr]
(* 94.16 + 2. eta16 *)


You can do that using rules:

Funt[T_, eta26_] := (-0.199 + 2. "eta26")*T^2 + "eta26" /. "eta26" -> eta26
Funt[2, 3]


26.204

• Thank you very much. It works fine for me
– Anh
Nov 13, 2019 at 8:34