Mathematica nonlinear fit problem

In summary, the individual is having trouble performing a complicated nonlinear fit with Mathematica due to a numerical integral in the fitted model. They have attempted to use the NonlinearRegress function but received an error message stating that the integrand evaluated to non-numerical values. The individual is seeking advice on how to make this work, but it appears that they may need to write their own fitting loop using test values for the parameters. They also mention that this issue is common and suggest using "?NumericQ" to solve it.
  • #1
evilcman
41
2
I would like to perform a complicated nonlinear fit with mathematica, which
involves a numerical integral in the fitted model. But i can't get it to work.
If I say something like:

NonlinearRegress[data, NIntegrate[f[x, p1, p2, y], {y, 0, 1}], {p1, p2}, x]

it says the integrand evaluated to non-numerical values. I guess this happens
because it tries to evaluate the fitted model symbolically.

How can I get this to work?
 
Physics news on Phys.org
  • #2
I'm not entirely sure you can unless you write your own loop to do the regression. Essentially the NIntegrate will only ever take numerical values, obviously, and will be evaluated first in the regression function. So either you supply values for your parameters so this can work, and then the regression won't, or vice versa. The only way i can see around this at the moment is do to your own fitting loop where you use test values of p1 p2. This way you can do a fit when p1 and p2 are defined, whereas the inbuilt function only takes a 'form' ie non-numeric.
 
  • #3
It is difficult to tell with the limited information you provided about f, p1, etc.

This kind of problem does show up in a variety of situations. I've tried to find a really good example that is doing almost exactly what you are doing and can't seem to find just the right one. If you Google for the three terms NIntegrate NumericQ and error you will find that the usual advice is to use "?NumericQ" to only match numeric values. That seems to usually solve the problem.
 
Last edited:

1. What is Mathematica and how does it relate to nonlinear fit problems?

Mathematica is a software program used for mathematical and statistical computations. It has a built-in function called NonlinearModelFit that can be used to find the best fit parameters for a nonlinear model based on a given set of data.

2. How does NonlinearModelFit work in Mathematica?

NonlinearModelFit uses an algorithm called Levenberg-Marquardt to iteratively adjust the parameters of the model to minimize the sum of squared residuals between the model predictions and the actual data points.

3. What are some common issues that can arise when using NonlinearModelFit in Mathematica?

Some common issues include: the model not converging, incorrect or unexpected parameter values, and overfitting the data. It is important to carefully choose the initial parameter values and to have a good understanding of the model and data before using NonlinearModelFit.

4. How can I improve the accuracy of my nonlinear fit using Mathematica?

There are a few ways to improve the accuracy of the fit. One option is to try different initial parameter values and/or use a different method for finding the best fit. It can also be helpful to have a larger dataset and to have a good understanding of the underlying model and its parameters.

5. Can I use Mathematica for nonlinear fit problems with large datasets?

Yes, Mathematica can handle large datasets for nonlinear fit problems. However, it may take longer to compute and you may need to adjust the initial parameter values and/or use a different method to find the best fit.

Similar threads

  • Calculus and Beyond Homework Help
Replies
6
Views
643
  • MATLAB, Maple, Mathematica, LaTeX
Replies
13
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Set Theory, Logic, Probability, Statistics
Replies
7
Views
477
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
3K
  • Set Theory, Logic, Probability, Statistics
Replies
28
Views
2K
  • Set Theory, Logic, Probability, Statistics
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
Back
Top