2
|
14375 Views
|
3 Replies
|
3 Total Likes
View groups...
Share
GROUPS:

# Numerical fitting to model that has Integral with no analytical solution

Posted 11 years ago
 I'm attempting to fit a model to my numerical dataset.  Unfortunately, the model contains rather complicated integral that cannot be solved analytically, but it can be solved numerically. Since the fitting is a numerical calculation, Mathematica should be able to find values for my fit parameters?  My attempts have been unsuccessful.  I either get errors saying it can't do the numerical integration because some of the parameters are not numbers, or I get the cell evaluating for days with no results (presumably because it's trying to find an analytical solution during each iteration of the fit).  My Mathematica knowledge is limited to just the basics. I've tried a few combinations of Integrate/NIntegrate and FindFit without any luck.I'm sure someone out there can help me.Here are some details:Data is intensity values in 2-D: {x, y, intensity}.model = S0*Integrate[Exp[(-\[Gamma])*(Sin^2)[\[Theta]]]/(1+(a*(x-x0)*Cos[\[Theta]] + b*(y-y0)*Sin[\[Theta]]*Cos[\[Phi]])^2),{\[Theta], -(Pi/2),Pi/2}, {\[Phi], 0, 2*Pi}]The parameters to fit are S0, gamma, a, b, x0, y0.  Theta and Phi will be integrated out of the model... assuming the numerical integration will be done.  All parameters and variables are real numbers. S0, gamma, a, and b, are all positive numbers.Do you have any ideas on how to execute this fit?
3 Replies
Sort By:
Posted 11 years ago
 Thanks, Sean!The ?NumericQ worked just fine!
Posted 11 years ago
 One way to do this is using ?NumericQ. Please see: http://support.wolfram.com/kb/3820For example let's say you wanted fit a function defined by an integral to a dataset, but the integral doesn't have a symbolic solution. To do this, first write a function of the independant (exogenous/"x" ) values and the parameters that gives the dependant (endogenous/"y") values. This is the model:f[parameter1_?NumericQ, parameter2_NumericQ.... x_?NumbericQ] := NIntegrate[......]This function will only evaluate when it is given values for the parameters and for x, ensuring that NIntegrate will evaluate. It can be given to a function like NonlinearModelFit:NonlinearModelFit[data, f[parameter1, parameter2.... x] , {parameter1, parameter2 ....}, x]An example of this technique is given under the documentation for NonlinearModelFit under Generalizations & Extensions:data = {{6.47, 3.65}, {7.43, 3.45}, {3.9, -2.94}, {4.8, -1.29}, {2.48, -0.35}, {6.32, 3.16}, {2.59, -1.19}, {9.13, -2.}, {3.81, -3.04}, {3.33, -2.68}};(* The model is defined using NDSolve, and so we need to use NumberQ or NumericQ*)model[a_?NumberQ, b_?NumberQ, c_?NumberQ] := Module[{y, x}, First[y /. NDSolve[{y''[x] + a y[x] == 0, y[0] == b, y'[0] == c}, y, {x, 0, 10}]]]nlm = NonlinearModelFit[data, model[a, b, c][x], {a, b, c}, x]Show[ListPlot[data], Plot[nlm[x], {x, 0, 10}, PlotStyle -> Green]]
Posted 11 years ago
 Do you have a small sample data set you can share?
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.