0
$\begingroup$

I used the following code for fitting but it does not produce an output.I kept it nearly 3 to 4 hours but it does not give any output. How should I make it correct?I have used two equation(f1,f2).I want to convolute f2 with Voight function and then add f1 with that and find the parameters. This is my data.

Data-[{0.720093, 0.295084}, {0.717593, 0.294154}, {0.71511, 
  0.293408}, {0.712644, 0.292561}, {0.710195, 0.291841}, {0.707763, 
  0.290859}, {0.705347, 0.289796}, {0.702948, 0.288597}, {0.700565, 
  0.287483}, {0.698198, 0.286434}, {0.695847, 0.285242}, {0.693512, 
  0.28415}, {0.691193, 0.283081}, {0.688889, 0.281928}, {0.6866, 
  0.28078}, {0.684327, 0.279592}, {0.682068, 0.278541}, {0.679825, 
  0.277436}, {0.677596, 0.27651}, {0.675381, 0.275654}, {0.673181, 
  0.274795}, {0.670996, 0.273949}, {0.668824, 0.272901}, {0.666667, 
  0.271992}, {0.664523, 0.271335}, {0.662393, 0.270664}, {0.660277, 
  0.269989}, {0.658174, 0.26921}, {0.656085, 0.268645}, {0.654008, 
  0.26808}, {0.651945, 0.267374}, {0.649895, 0.266843}, {0.647858, 
  0.266955}, {0.645833, 0.267217}, {0.643821, 0.267661}, {0.641822, 
  0.267598}, {0.639835, 0.267401}, {0.63786, 0.267703}, {0.635897, 
  0.268113}, {0.633947, 0.269681}, {0.632008, 0.27114}, {0.630081, 
  0.272627}, {0.628166, 0.274489}, {0.626263, 0.276107}, {0.624371, 
  0.277585}, {0.62249, 0.278766}, {0.620621, 0.280244}, {0.618762, 
  0.281839}, {0.616915, 0.283631}, {0.615079, 0.284915}, {0.613254, 
  0.285762}, {0.61144, 0.286192}, {0.609636, 0.288746}, {0.607843, 
  0.29093}, {0.606061, 0.292403}, {0.604288, 0.293922}, {0.602527, 
  0.297144}, {0.600775, 0.299701}, {0.599034, 0.302432}, {0.597303, 
  0.304511}, {0.595581, 0.309842}, {0.59387, 0.313888}, {0.592168, 
  0.318189}, {0.590476, 0.319657}, {0.588794, 0.320562}, {0.587121, 
  0.321366}, {0.585458, 0.321272}, {0.583804, 0.31859}, {0.58216, 
  0.315947}, {0.580524, 0.313623}, {0.578898, 0.310534}, {0.577281, 
  0.304952}, {0.575673, 0.298553}, {0.574074, 0.290369}, {0.572484, 
  0.279767}, {0.570902, 0.26778}, {0.56933, 0.2571}, {0.567766, 
  0.244668}, {0.56621, 0.22961}, {0.564663, 0.215466}, {0.563124, 
  0.200814}, {0.561594, 0.184229}, {0.560072, 0.169114}, {0.558559, 
  0.153148}, {0.557053, 0.137587}, {0.555556, 0.122651}, {0.548187, 
  0.108596}, {0.546737, 0.092986}, {0.545295, 0.0785259}, {0.54386, 
  0.0709461}, {0.542432, 0.0609015}, {0.541012, 0.0524228}, {0.5396, 
  0.0465767}, {0.538194, 0.0402518}, {0.536797, 0.0339568}, {0.535406,
   0.0290519}, {0.534022, 0.0210021}, {0.532646, 
  0.0163296}, {0.531277, 0.0125908}, {0.529915, 0.011545}, {0.528559, 
  0.00787535}, {0.527211, 0.00539227}, {0.525869, 
  0.00218363}, {0.524535, -4.67229*10^-6}}]


    data = Import["E:\\FITTING DATA\\Sheet1.txt", "Table"]; 
        original = 
         ListLinePlot[data, AxesLabel -> {count, intensity}, 
          PlotStyle -> {Red}, Frame -> True]
        f1 = a*UnitStep[x - b]*c*
          Sqrt[x - b]*(Pi*Sqrt[d]/Sqrt[x - b]*Exp[Pi*Sqrt[d]/Sqrt[x - b]])/
           Sinh[Pi*Sqrt[d]/Sqrt[x - b]]
        f2 = a*d*Sum[(4*Pi)/n^3*DiracDelta[x - b + d/n^2], {n, 1, 1}]
        f3 = Convolve[
          a*d*Sum[(4*Pi)/n^3*DiracDelta[x - b + d/n^2], {n, 1, 1}], 
          Re[Erfc[(\[Delta] + I*x)/(Sqrt[2]*\[Sigma])]/
            E^((x - I*\[Delta])^2/(2*\[Sigma]^2))], x, y]
        fit2 = NonlinearModelFit[
           data, {a*UnitStep[y - b]*c*
              Sqrt[y - 
                b]*(Pi*Sqrt[d]/Sqrt[y - b]*Exp[Pi*Sqrt[d]/Sqrt[y - b]])/
               Sinh[Pi*Sqrt[d]/Sqrt[y - b]] + 

             Convolve[
              a*d*Sum[(4*Pi)/n^3*DiracDelta[x - b + d/n^2], {n, 1, 1}], 
              Re[Erfc[(\[Delta] + I*x)/(Sqrt[2]*\[Sigma])]/
                E^((x - I*\[Delta])^2/(2*\[Sigma]^2))], x, y], 
            b < Min[data[[All, 1]]], 
                 Inequality[10, Less, a, Greater, 15], 0.01 < c < 0.1, 
            Inequality[0.001, Less, d, Greater, 0.01]}, {{a, 10}, {b, -1}, c, 
            d, \[Delta], \[Sigma]}, y]; 
        fit2["BestFitParameters"]
        Show[ListPlot[data, PlotStyle -> {Red}, 
          AxesLabel -> {count, intensity}], 
         Plot[fit2[y], {y, 1.3, 0.55}, PlotStyle -> {Blue}], Frame -> True]
$\endgroup$
1
$\begingroup$

Inequality[10, Less, a, Greater, 15] is 10 < a && a > 15

Inequality[0.001, Less, d, Greater, 0.01] is 0.001 < d && d > 0.01

I doubt that is what you meant. I'm guessing you meant 10<a<15 and 0.001<d<0.01

Note: Thank you for your raw data. It would have been impossible to do this without that.

This

data =
{{0.720093, 0.295084}, {0.717593, 0.294154}, {0.71511, 0.293408}, {0.712644, 0.292561},
 {0.710195, 0.291841}, {0.707763, 0.290859}, {0.705347, 0.289796}, {0.702948, 0.288597},
 {0.700565, 0.287483}, {0.698198, 0.286434}, {0.695847, 0.285242}, {0.693512, 0.28415},
 {0.691193, 0.283081}, {0.688889, 0.281928}, {0.6866, 0.28078}, {0.684327, 0.279592},
 {0.682068, 0.278541}, {0.679825, 0.277436}, {0.677596, 0.27651}, {0.675381, 0.275654},
 {0.673181, 0.274795}, {0.670996, 0.273949}, {0.668824, 0.272901}, {0.666667, 0.271992},
 {0.664523, 0.271335}, {0.662393, 0.270664}, {0.660277, 0.269989}, {0.658174, 0.26921},
 {0.656085, 0.268645}, {0.654008, 0.26808}, {0.651945, 0.267374}, {0.649895, 0.266843},
 {0.647858, 0.266955}, {0.645833, 0.267217}, {0.643821, 0.267661}, {0.641822, 0.267598},
 {0.639835, 0.267401}, {0.63786, 0.267703}, {0.635897, 0.268113},  {0.633947, 0.269681},
 {0.632008, 0.27114}, {0.630081, 0.272627}, {0.628166, 0.274489}, {0.626263, 0.276107},
 {0.624371, 0.277585}, {0.62249, 0.278766}, {0.620621, 0.280244}, {0.618762, 0.281839},
 {0.616915, 0.283631}, {0.615079, 0.284915}, {0.613254, 0.285762}, {0.61144, 0.286192},
 {0.609636, 0.288746}, {0.607843, 0.29093}, {0.606061, 0.292403}, {0.604288, 0.293922},
 {0.602527, 0.297144}, {0.600775, 0.299701}, {0.599034, 0.302432}, {0.597303, 0.304511},
 {0.595581, 0.309842}, {0.59387, 0.313888}, {0.592168, 0.318189}, {0.590476, 0.319657},
 {0.588794, 0.320562}, {0.587121, 0.321366}, {0.585458, 0.321272}, {0.583804, 0.31859},
 {0.58216, 0.315947}, {0.580524, 0.313623}, {0.578898, 0.310534}, {0.577281, 0.304952},
 {0.575673, 0.298553}, {0.574074, 0.290369}, {0.572484, 0.279767}, {0.570902, 0.26778},
 {0.56933, 0.2571}, {0.567766, 0.244668}, {0.56621, 0.22961}, {0.564663, 0.215466},
 {0.563124, 0.200814}, {0.561594, 0.184229}, {0.560072, 0.169114}, {0.558559, 0.153148},
 {0.557053, 0.137587}, {0.555556, 0.122651}, {0.548187, 0.108596}, {0.546737, 0.092986},
 {0.545295, 0.0785259}, {0.54386, 0.0709461}, {0.542432, 0.0609015}, {0.541012, 0.0524228},
 {0.5396, 0.0465767}, {0.538194, 0.0402518}, {0.536797, 0.0339568}, {0.535406, 0.0290519},
 {0.534022, 0.0210021}, {0.532646, 0.0163296}, {0.531277, 0.0125908}, {0.529915, 0.011545},
 {0.528559, 0.00787535}, {0.527211, 0.00539227}, {0.525869, 0.00218363}, {0.524535, -4.67229*10^-6}};
(*data=Import["E:\\FITTING DATA\\Sheet1.txt","Table"];*)
Print[original = ListLinePlot[data, AxesLabel -> {count, intensity}, 
  PlotStyle -> {Red}, Frame -> True]];
f1 = a*UnitStep[y - b]*c*Sqrt[y - b]*(Pi*Sqrt[d]/Sqrt[y - b]*
  Exp[Pi*Sqrt[d]/Sqrt[y - b]])/Sinh[Pi*Sqrt[d]/Sqrt[y - b]];
f2 = a*d*Sum[(4*Pi)/n^3*DiracDelta[x - b + d/n^2], {n, 1, 1}];
f3 = Convolve[f2, Re[Erfc[(δ + I*x)/(Sqrt[2]*σ)]/E^((x - I*δ)^2/(2*σ^2))], x, y];
system = {f1+f3, b<Min[data[[All, 1]]], 10<a<15, 0.01<c<0.1, 0.001<d<0.01};
fit2 = NonlinearModelFit[data, system, {{a, 10}, {b, -1}, c, d, δ, σ}, y];
Print[fit2["BestFitParameters"]];
Show[ListPlot[data, PlotStyle -> {Red}, AxesLabel -> {count, intensity}],
  Plot[fit2[y], {y, 1.3, 0.55}, PlotStyle -> {Blue}], Frame -> True]

enter image description here

finishes in about 20 seconds.

I am guessing you need to adjust your model or perhaps set some initial parameters to get a better fit to your data.

I believe the reason this is slow is almost exactly the same reason your previous question was slow. I sped this one up using exactly the same technique as used with your previous question.

Please check all this very very carefully to try to make certain that I have not made any mistakes.

$\endgroup$
  • $\begingroup$ Thank you very much. Is it possible for me to get good fitting by changing the initial parameters? $\endgroup$ – Tharaka Oct 22 '18 at 18:00
  • $\begingroup$ That is a more difficult question to answer. I can't tell whether you are only trying to fit a portion of the data. I can't tell whether you have selected an appropriate model for that data. I don't know what you are really trying to accomplish. Because of all of that I haven't even looked at whether I could change what you are trying to do. $\endgroup$ – Bill Oct 22 '18 at 18:11
  • $\begingroup$ How do I apply range for my parameters? $\endgroup$ – Tharaka Oct 24 '18 at 2:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.