0
$\begingroup$

I am trying to optimize the following function further in terms of speed while maintaining the given Precision and correctness.

The function decribes the two dimensional convolution of a sum of Bessel functions and a Gaussian along one axis.

    model[Q_?NumericQ, f_?NumericQ, sigma_?NumericQ, A_?NumericQ,y_?NumericQ] :=
Log10[0.25*NIntegrate[Abs[Sum[(I*f)^(j - 1)*(1/(Sqrt[(x - y)^2 + z^2]))^(j)*BesselJ[j, 2*Q*Sqrt[(x - y)^2 + z^2]], {j, 1, 20}]]^2*A*Exp[-(x^2 + z^2)/((sigma)^2)],
 {x, -Infinity,Infinity}, {z, -Infinity, Infinity}, PrecisionGoal -> 4, Method -> {"EvenOddSubdivision", "VerifyConvergence" -> False, Method -> "LocalAdaptive"}]]

I have tested out various Methods for the function and already a achieved a great improvement compared to using standard methods. However, I am curious if there are even more improvements possible.

This function is used to fit a certain set of data which can take up to several hours, example:

    nlm1 = NonlinearModelFit[data1, {model[Q, f, sigma, A, y]}, {{Q, 1.76}, {f, 2.4}, {sigma, 0.2}, {A, 85000}}, y,
EvaluationMonitor :> Print["Q=", Q, ". f=", f, ". sigma=", sigma, ". A=", A]][  "ParameterTable"]

Thanks!

$\endgroup$
2
  • 1
    $\begingroup$ It would be helpful if you provide your data for a minimal working example. $\endgroup$ Nov 16 '21 at 13:17
  • $\begingroup$ Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. $\endgroup$
    – bbgodfrey
    Nov 16 '21 at 13:49

Your Answer

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

Browse other questions tagged or ask your own question.