# Fitting an equation to data

If I have the followind data:

data={{45, 2.93495}, {50, 2.94697}, {55, 1.9801}, {60,0.734437}, {65, -0.0128219}, {70, -0.695535}, {75,-1.35939}, {80,-1.47567}}


where the x values are Temperature in Celsius (T) and the y values are log10 of time (t).

Question:

1. How can I fit the following equation to the data and find the fitting parameters K1 and K2?

where log (tind) is the log in base 10 of time (y axis of my data), T is the x axis of my data and T0=259.246 (*Kelvin*), B=2595.89, Tm=433.15 (*Kelvin*)

I have been trying the following but it does not work:

T0=259.246 (*Kelvin*);
B=2595.89;
Tm=433.15 (*Kelvin*);
eq = k1 - 2*Log10[T] + (k2/(2.303*T^3*(Tm - T)^2)) + 0.75*(B/(2.303*(T - T0))) (*T would be the x axis of my data*)
nlmtind = NonlinearModelFit[data, eq, {k1, k2}, x]


Notice that the x axis should be converted to kelvin (+273.15) for consistency of units

• In your code Tm,T0,B are not specified and x in the fit is T, I presume. This works: nlmtind = NonlinearModelFit[data, eq, {k1, k2, Tm, T0, B}, T] Commented May 19, 2021 at 20:16
• @Andrzej thanks for your comment. Tm, T0 and B are numbers shown above. I put this numbers in the code to make it more specific. Unfortunately, your suggestions is not working.
– John
Commented May 19, 2021 at 20:19

Try this:

data = {{45, 2.93495}, {50, 2.94697}, {55, 1.9801}, {60,
0.734437}, {65, -0.0128219}, {70, -0.695535}, {75, -1.35939}, \
{80, -1.47567}};
y = k1 - 2 Log[x, 10] + k2/2.303/(x^3 (Tm - x)^2) +
0.75 B/2.303/(x - T0) /. {T0 -> 259.246, B -> 2595.89,
Tm -> 433.15};

fun[x_] = NonlinearModelFit[data, y, {k1, k2}, x] // Normal;

Plot[fun[x], {x, 45, 80}, Epilog -> Point[data]]


If you want to force the k1 and k2 to be positive, the fit will be horrible:

t = NonlinearModelFit[data, {y, k1 > 0, k2 > 0}, {k1, k2}, x];
t["BestFitParameters"]

(* {k1 -> 11.496, k2 -> 1874.25} *)


k1 and k2 are now positive, but the fit is bad:

fun[x_] = t // Normal
Plot[fun[x], {x, 45, 80}, Epilog -> Point[data], PlotRange -> {-1, 7}]


• Thank you Daniel! One quick question: How can I make k1 and k2 be greater than 0? I am trying this from your code: NonlinearModelFit[data, y, {{k1>0}, {k2>0}}, x] but it does not seem to force those fitting parameters to be greater than 0
– John
Commented May 19, 2021 at 21:06
• Try fun[x_] = NonlinearModelFit[data, {y, k1 > 0, k2 > 0}, {k1, k2}, x] Commented May 20, 2021 at 0:52
• I made an addendum to my answer. To request the parameters to be positive gives an unusable fit. Commented May 20, 2021 at 7:26