# Difficulty with FindFit with complex equation

I want to fit the following equation for my experimental data. I used the following code but it does not give the answer.

nlm = NonlinearModelFit[
data, {Convolve[
a*UnitStep[x - b]*c*Sqrt[x - b]*
Divide[Pi*Divide[Sqrt[d], Sqrt[x - b]]*
Exp[Pi*Divide[Sqrt[d], Sqrt[x - b]]],
Sinh[Pi*Divide[Sqrt[d], Sqrt[x - b]]]] +
a*d*Sum[Divide[4*Pi, n^3]*DiracDelta[x - b + d/n^2], {n, 1, 1}],
VoigtDistribution, x, y], b < Min[data[[All, 1]]],
b < Min[data[[All, 1]]]}, {{a, 10}, {b, -1}, c, d}, x];
nlm["BestFitParameters"]

• You'll need to add a restriction for b such as b < 1 (if you don't specify the x values) or b < Min[x] (if you do specify the x values in the dataset). (I suspect the extra comma at the end of FindFit is a typo entered here.)
– JimB
Sep 21, 2018 at 23:43
• Thank you,FindFit[l1, aUnitStep[x - b]*cSqrt[x - b]* Divide[PiDivide[c, Sqrt[x - b]]*Exp[PiDivide[c, Sqrt[x - b]]], Sinh[Pi*Divide[c, Sqrt[x - b]]]], x2, {a, b, c}],I corrected it.but out put is "Search specification 1.37777777777778 without variables should be a \ list with 1 to 4 elements"What does it mean.What is the wrong with this Sep 22, 2018 at 3:28
• You'll need to show at least a subset of what you have in data (or l1 as you're calling now).
– JimB
Sep 22, 2018 at 4:33
• Thank you very much, What does it mean, Could you please provide an example code. It is a great help for me. Sep 23, 2018 at 15:02
• Your code works fine with made-up data in the expected format. That suggests to me that there's something special about your data - either the values or the structure. I don't think anyone can help until you show at least some of data or l1.
– JimB
Sep 23, 2018 at 17:21

It appears that you are feeding FindFit with just the response variable and the predictor variable is assumed to take on the values 1, 2, ....

If so, then your error message allows one to reconstruct some of the data:

y = {2.15658, 2.16407, 2.1716, 2.17916, 2.18675, 2.19437, 2.20203,
2.20973, 2.21746, 2.22523, 2.23304, 2.24088, 2.24876, 2.25668,
2.26464, 2.27264, 2.28068, 2.43294, 2.44186, 2.45084, 2.45986,
2.46894, 2.47808, 2.48727, 2.49652, 2.50583, 2.51519, 2.52462,
2.5341, 2.54365, 2.55326, 2.56293, 2.57266}

data = Transpose[{Join[Range, 34 + Range], y}]


A plot of the data reveals a an uninteresting function:

ListPlot[data] Your complicated function is much too complicated for the data. Here is the fit using NonlinearModelFit and assuming b < data[[All,1]]:

nlm = NonlinearModelFit[
data, {a*UnitStep[x - b]*c*Sqrt[x - b]*
Divide[Pi*Divide[c, Sqrt[x - b]]*Exp[Pi*Divide[c, Sqrt[x - b]]],
Sinh[Pi*Divide[c, Sqrt[x - b]]]],
b < Min[data[[All, 1]]]}, {{a, 10}, {b, -1}, c}, x];
nlm["BestFitParameters"]
(* {a -> 8.46225, b -> -113.529, c -> 0.0235281} *)


But these estimates are not to be trusted. Not because of Mathematica doing something wrong but because the model is much too complicated for the available data. This conclusion is supported by an examination of the correlations among the parameter estimates:

nlm["CorrelationMatrix"] // MatrixForm


$$\left( \begin{array}{ccc} 1. & -0.999855 & -1. \\ -0.999855 & 1. & 0.999855 \\ -1. & 0.999855 & 1. \\ \end{array} \right)$$

The high correlations suggest that you really only have at most 2 parameters that can be estimated rather than 3.

I can't duplicate the error you're getting using my guess as to what is a subset of what your data looks like. Maybe if you give the whole dataset, then one could track down the reason for the error message. But in any event, your model is way too complicated for the data.

Update

With the sample data the same situation exists: the proposed model is too complicated for the data.

data = {{0.807292, 0.334473}, {0.80415, 0.333431}, {0.801034,
0.332193}, {0.797941, 0.331024}, {0.794872, 0.329786}, {0.791826,
0.328846}, {0.788804, 0.327797}, {0.785805, 0.326909}, {0.782828,
0.32591}, {0.779874, 0.324893}, {0.776942, 0.323883}, {0.774032,
0.322896}, {0.771144, 0.321917}, {0.768278, 0.320953}, {0.765432,
0.319928}, {0.762608, 0.318885}, {0.759804, 0.317574}, {0.757021,
0.316674}, {0.754258, 0.315271}};

nlm = NonlinearModelFit[
data, {a*UnitStep[x - b]*c*Sqrt[x - b]*
Divide[Pi*Divide[c, Sqrt[x - b]]*Exp[Pi*Divide[c, Sqrt[x - b]]],
Sinh[Pi*Divide[c, Sqrt[x - b]]]],
b < Min[data[[All, 1]]]}, {a, {b, -1}, c}, x,
MaxIterations -> 1000];
nlm["BestFitParameters"]
(* {a -> 215.58, b -> 0.322036, c -> 0.00220429} *)
nlm["CorrelationMatrix"] // MatrixForm
`

$$\left( \begin{array}{ccc} 1. & -0.999969 & -1. \\ -0.999969 & 1. & 0.99997 \\ -1. & 0.99997 & 1. \\ \end{array} \right)$$

At this point I think just fitting a straight line is all that is warranted. If the complicated model has some physical meaning and you know it to be correct, then the question to ask is "Why doesn't the data support that model?"

• Thank you very much. Sep 24, 2018 at 3:45
• That works for me, Thank you very much. I want to convolve two equation, then I want to find the parameters. But it doesn't give the answer and Takes too much time. What is the wrong with my code? Sep 24, 2018 at 19:16
• I have entered my new code. Sep 24, 2018 at 19:48