# How do I run 1-855 data points( imported from excel sheet) into a formula to obtain value for each data point?

I am very new to Mathematica and I just couldn't figure out the solution for the following problem.

I have two columns in an Excel file. I have imported the 1st column as temp (1- 855 data points), and the 2nd as den (1-855 data points). I am trying to calculate the ellipticity (ellip, last formula) for each value of temp and den However, my script only returns one value. I need the ellip values for each of my tempand den concentrations.

My question is how do I run 1-855 data points of temp and den into the ellip formula so that it will return values for each data point?

Below is my Mathematica script.

a = -29846.66713137483;

b = 49.10083342826049;

c = -5927.651357897106;

d = 9402.228131251579;

e = -36.722337085166785;

f = 0.029490823878660512;

g = -528.5106658275561;

dCp = 19.731822683160715;

dH = 0.2566239190680801;

m = 0.995288747060038;

Tm = 372.92653842275854;

temp= Import["/Users/Justin Yeoh/Documents/Professor \ Szyperski/Research/CD/CombinedMelt_copy.xlsx", {"Data", 1, Range[1, 855], {1}}];

den = Import["/Users/Justin Yeoh/Documents/Professor \ Szyperski/Research/CD/CombinedMelt_copy.xlsx", {"Data", 1,Range[1, 855], {2}}];

thetaF[a_, b_, c_, temp_, den_] := a + b*temp + c*den;

thetaU[d_, e_, f_, g_, temp_, den_] := d + e*temp + f*temp^2 + g*den;

dG[dH_, dCP_, m_, Tm_, temp_, den_] :=
dH*(1 - temp/Tm) - dCP*((Tm - temp) + temp*Log[temp/Tm]) + (-m)*den;

ellip[a_, b_, c_, d_, e_, f_, g_, dH_, dCP_, m_, Tm_, temp_,den_] :=
(thetaF[a, b, c, temp, den] +
thetaU[d, e, f, g, temp, den] Exp[-dG[dH, dCP, m, Tm, temp, den]/(.00198 temp)])/
(1 + Exp[-dG[dH, dCP, m, Tm, temp, den]/(.00198*temp)])

• What is the format of the data in your temp and den variables? – bill s Feb 18 '16 at 22:28
• Could you try escaping your file name/paths? i.e. ["C:\\Users\\peter\\data.xslx"] – Peter Roberge Feb 18 '16 at 22:51
• Hi David, what is format of data? I am sorry I only know that both variables are in xlsx. – justin yeoh Feb 18 '16 at 22:52
• When you import your data, look at it carefully. For example, FullForm[temp] will show you exactly what you have imported. – bill s Feb 18 '16 at 23:01
• Hi Peter, I tried to escape the file name /paths. Unfortunately, I still get just one value for my ellip. – justin yeoh Feb 18 '16 at 23:02

In cases like yours, I am a great believer in simplifying the code by using With to insert the parameters into the function definitions rather than carrying a mess of them around in arguments. Here is how this idea applies to your code.

With[{
a = -29846.66713137483,
b = 49.10083342826049,
c = -5927.651357897106,
d = 9402.228131251579,
e = -36.722337085166785,
f = 0.029490823878660512,
g = -528.5106658275561,
dCP = 19.731822683160715,
dH = 0.2566239190680801,
m = 0.995288747060038,
Tm = 372.92653842275854
},
thetaF[temp_, den_] := a + b temp + c den;
thetaU[temp_, den_] := d + e temp + f temp^2 + g den;
dG[temp_, den_] :=
dH (1 - temp/Tm) - dCP ((Tm - temp) + temp Log[temp/Tm]) + (-m) den;
ellip[temp_, den_] :=
With[{u = Exp[-dG[temp, den]/(.00198 temp)]},
(thetaF[temp, den] + u thetaU[temp, den])/(1 + u)]]


The advantage of making the definitions this way is that they are clearer to the reader of the code and the code actually performs somewhat better.

With the above you can get your values, presuming that temp and den are lists of real numbers, with

Thread[ellip[temp, den]]


### Update

The above is fine if the parameters are truly constants, but you might do another set of experiments with a different set of parameters. Let's look into handling this more general problem.

I will start by defining a function that builds the ellis function from when given the parameters.

ellipticity[a_, b_, c_, d_, e_, f_, g_, dCP_, dH_, m_, Tm_] :=
(
Clear[thetaF, thetaU, dG, ellip];
thetaF[temp_, den_] := a + b temp + c den;
thetaU[temp_, den_] := d + e temp + f temp^2 + g den;
dG[temp_, den_] :=
dH (1 - temp/Tm) - dCP ((Tm - temp) + temp Log[temp/Tm]) + (-m) den;
ellip[temp_, den_] :=
With[{u = Exp[-dG[temp, den]/(.00198 temp)]},
(thetaF[temp, den] + u thetaU[temp, den])/(1 + u)];
ellip
)


Note that ellipticity builds a new set of functions returns a the ellip function every time it is called. Returning ellip is a matter of convenience.

Now ellipticity can be used in the same way a ellis was above, but the parameters are given to it as arguments.

The follow demonstrates usage. I have fabricated a small test data set, but not knowing what are reasonable ranges for the temp and den, the results are not to be taken seriously.

Module[{n = 6, temp, den},
SeedRandom;
{temp, den} = {RandomReal[{50., 99.}, n], RandomReal[1., n]};
With[{
a = -29846.66713137483, b = 49.10083342826049,
c = -5927.651357897106, d = 9402.228131251579,
e = -36.722337085166785, f = 0.029490823878660512,
g = -528.5106658275561, dCP = 19.731822683160715,
dH = 0.2566239190680801, m = 0.995288747060038,
Tm = 372.92653842275854
},
Thread[ellipticity[a, b, c, d, e, f, g, dCP, dH, m, Tm][temp, den]]]]


{6047.8742264, 7334.1625993, 6168.1045631, 6961.3344009, 7132.5852188, 7135.6808087}

Whether or not you would want to have a master function such as ellipticity is a matter of coding style and coding taste. But such functions can be useful and Mathematica has no problem dealing with a function call where the head is in itself a function call. Mathematica evaluates an expression's head before it evaluates the expression's arguments. In fact, the head expression of a function call may reasonably be regarded as argument zero the call.

If temp and den have all 855 data points then you can use Thread since all other parameters are scalars the dimensions of temp and den are equal.

Thread@ellip[a, b, c, d, e, f, g, dH, dCP, m, Tm, temp, den]


If you are having issues with the Excel filename then try SystemDialogInput.

{temp, den} = Transpose@