I’m trying to fit a model curve to some data by performing a chi square minimisation wrt three parameters $ a,b$ and $ NN$ . The trouble I am having is that the variables with which I want to minimise the chi square with respect to appear in an integral. I attach the code I am working with.
Needs["ErrorBarPlots`"] MasData5 = {{{44.8, 47.5}, ErrorBar[4.0]}, {{54.8, 50.1}, ErrorBar[4.2]}, {{64.8, 61.7}, ErrorBar[5.1]}, {{74.8, 64.8}, ErrorBar[5.5]}, {{84.9, 75}, ErrorBar[6.2]}, {{94.9, 81.2}, ErrorBar[6.7]}, {{104.9, 85.3}, ErrorBar[7.1]}, {{119.5, 94.5}, ErrorBar[7.5]}, {{144.1, 101.5}, ErrorBar[8.3]}, {{144.9, 101.9}, ErrorBar[10.9]}, {{162.5, 117.8}, ErrorBar[12.8]}, {{177.3, 130.2}, ErrorBar[13.4]}, {{194.8, 147.7}, ErrorBar[17.1]}, {{219.6, 137.4}, ErrorBar[20.1]}, {{244.8, 176.6}, ErrorBar[20.3]}, {{267.2, 178.7}, ErrorBar[21.1]}, {{292.3, 200.4}, ErrorBar[29.1]}, {{60, 55.8}, ErrorBar[4.838]}, {{80, 66.6}, ErrorBar[7.280]}, {{100, 73.4}, ErrorBar[6.426]}, {{120, 86.7}, ErrorBar[7.245]}, {{140, 104}, ErrorBar[12.083]}, {{160, 110}, ErrorBar[16.279]}, {{42.5, 43.8}, ErrorBar[3.482]}, {{55, 57.2}, ErrorBar[3.980]}, {{65, 62.5}, ErrorBar[4.614]}, {{75, 68.9}, ErrorBar[5.197]}, {{85, 72.1}, ErrorBar[5.523]}, {{100, 81.9}, ErrorBar[5.368]}, {{117.5, 95.7}, ErrorBar[6.277]}, {{132.5, 103.9}, ErrorBar[6.912]}, {{155, 115}, ErrorBar[7.920]}, {{185, 129.1}, ErrorBar[9.192]}, {{215, 141.7}, ErrorBar[10.666]}, {{245, 140.3}, ErrorBar[14.526]}, {{275, 189}, ErrorBar[24.274]}, {{49, 39.2}, ErrorBar[10]}, {{86, 75.7}, ErrorBar[14.414]}, {{167, 118}, ErrorBar[22.828]}, {{43.2, 50.7}, ErrorBar[1.5]}, {{50, 59.5}, ErrorBar[1.4]}, {{57.3, 61.8}, ErrorBar[1.9]}, {{65.3, 67.6}, ErrorBar[1.7]}, {{73.9, 72.4}, ErrorBar[1.9]}, {{83.2, 79.9}, ErrorBar[2.3]}, {{93.3, 84.4}, ErrorBar[2.1]}, {{104.3, 86.7}, ErrorBar[2.7]}, {{47.9, 55.4}, ErrorBar[2.1]}, {{68.4, 66.4}, ErrorBar[2.9]}}; (*this is the experimental data *) gamma = 5.55*^-6; MJpsi = 3.1; alphaem = 1/137; alphas[k_] = 4*Pi/9/Log[k/lambda]; lambda = 0.09; Ca = 3; (*list of constants and k dependent function alphas*) xg = NN*((4*qbar)/((4*qbar - MJpsi^2) + w^2))^(-a)*(qbar)^b*Exp[Sqrt[16*Ca/9*Log[(4*qbar - MJpsi^2 + w^2)/(4*qbar)]* Log[Log[qbar/lambda]/Log[qo/lambda]]]] (* def xg, appearing in below *) F5[w_] = 3.89379*^5*1/4.5/16*4*Pi^3*MJpsi^3* gamma/12/ alphaem*(Nintegrate[ alphas[k_]/qbar/(qbar + k_)* D[(2^(2*(D[Log[xg], Log[1/(((4*qbar))/((4*qbar - MJpsi^2) + w^2))]]) + 3)/Sqrt[Pi]* Gamma[D[Log[xg], Log[1/(((4*qbar))/((4*qbar - MJpsi^2) + w^2))]] + 5/2]/ Gamma[ D[Log[xg], Log[1/(((4*qbar))/((4*qbar - MJpsi^2) + w^2))]] + 4])*NN* (((4*qbar))/((4*qbar - MJpsi^2) + w^2))^(-a)*(k_)^b* Exp[Sqrt[ 16*Ca/9*Log[(4*qbar - MJpsi^2 + w^2)/(4*qbar)]* Log[Log[k_/lambda]/Log[qo/lambda]]]], k_], {k_, qo, (w^2 - MJpsi^2)/4}] + 0.118/qbar/qo*Log[(qbar + qo)/qbar]* NN* ((4*qbar)/((4*qbar - MJpsi^2) + w^2))^(-a)*(qo)^ b*(2^(2*(D[Log[xg], Log[1/(((4*qbar))/((4*qbar - MJpsi^2) + w^2))]]) + 3)/Sqrt[Pi]* Gamma[D[Log[xg], Log[1/(((4*qbar))/((4*qbar - MJpsi^2) + w^2))]] + 5/2]/ Gamma[D[Log[xg], Log[1/(((4*qbar))/((4*qbar - MJpsi^2) + w^2))]] + 4]))^2; /. { qbar -> 2.4025, qo -> 2} (*my model function - involves a numerical integration over variable k_ *) chisq5 = Sum[((MasData5[[k]][[1]][[2]] - F5[MasData5[[k]][[1]][[1]]])/ MasData5[[k]][[2]][[1]])^2, {k, 1, Length[MasData5]}]; (*def of my chi square function *) rr = Minimize[chisq5, {a, b, NN}] (*minimise chi square wrt a,b,NN *)
This gives me an error that the output is not a number at {a,b,NN}. Can mathematica handle minimisation of a function wrt variables that are involved in an integration? I would have thought yes as the numerical integration involved is simply a nested operation but perhaps I have to adapt my syntax. Or perhaps the error is simply something else I overlooked? Thanks for any pointers.