Curve fitting in Mathematica with FindMinimum function

In summary, the person is asking for help with fitting a function to experimental data. They describe how to adapt a solution from a previous post to their problem. They mention that it is more convenient to define "Residual" in terms of an n-dimensional vector. They then use the FindMinimum function to fit the residual to the experimental data.
  • #1
grzesz
2
0
Hello,
I attempt to fit experimental data using FindMinimum function with Levenberg-Marquardt (LM) method. I know that the problem can be solved with FindFit function (or other methods of finding minimum), but I really have to use FindMinimum function and LM method. Therefore, I would appreciate if someone could explain how to use FindMinimum function to fit a set of experimental points (with LM method).

Let’s say that I have to fit a function f(x,a,b), where a and b are fit parameters, to a dataset that looks like this:{{x1,y1},...,{xn,yn}}.
1. How to define "Residual"? Is this a vector V of a form {y1-f(x1,a,b),...,yn-f(xn,a,b)}?
2. Is it necessary to define also the function f in FindMinimum[f,...]? How to do this?
I would be grateful for any help with this issue.
Regards,
G.
 
Physics news on Phys.org
  • #2
I see you have asked this same question in a number of other places and for some reason do not seem to be getting any replies.

Perhaps you can see how to adapt this to your problem.

In[1]:= dataset={{1,2},{3,7},{4,3}};
f[x_,a_,b_]:=a x+b;
sumsquare=Total[Map[(#[[2]]-f[#[[1]],a,b])^2&,dataset]]
Out[3]= (3-4a-b)^2+(7-3a-b)^2+(2-a-b)^2

In[4]:= FindMinimum[sumsquare,{{a,7},{b,2}},Method->LevenbergMarquardt]
Out[4]= {12.0714,{a->0.642857,b->2.28571}}

In[5]:= {a,b}/.Last[%]
Out[5]= {0.642857,2.28571}
 
  • #3
First of all thank you very much for your help. I tried this solution and it works very well. However, for my problem it was more conveniently to define „Residual” in the way that I described in my previous post (as an n-dimensional vector V). After that I just used formula:

FindMinimum[(0),{a, a0}, {b, b0}, Method->{“LevenbergMarquardt”, “Residual” -> V}]

The problem was that I did not know how to define the objective function. After some time I figured out that it is unnecessary. You can use “0” instead the objective function and the algorithm works pretty well.
 

FAQ: Curve fitting in Mathematica with FindMinimum function

1. What is curve fitting and why is it important in Mathematica?

Curve fitting is a statistical method used to find the best fit line or curve for a set of data points. It is important in Mathematica because it allows for the creation of accurate models and predictions based on experimental data.

2. How does the FindMinimum function work in curve fitting?

The FindMinimum function in Mathematica uses the method of least squares to find the best fit line or curve for a given set of data points. It minimizes the sum of the squared differences between the observed data and the predicted values from the model.

3. What are the main parameters to consider when using the FindMinimum function for curve fitting?

The main parameters to consider are the initial values for the fitting parameters and the choice of fitting function. The initial values can greatly affect the accuracy of the fit, and the fitting function should be chosen based on the type of data and the desired model.

4. How can I evaluate the accuracy of the curve fit in Mathematica?

The accuracy of the curve fit can be evaluated by examining the residuals, which are the differences between the observed data and the predicted values from the model. A smaller residual value indicates a better fit.

5. Are there any tips for improving the accuracy of the curve fit in Mathematica?

Yes, some tips include choosing appropriate initial values for the fitting parameters, trying different fitting functions, and increasing the number of iterations in the FindMinimum function. It is also important to visually inspect the fit and make any necessary adjustments to improve its accuracy.

Similar threads

Replies
1
Views
2K
Replies
1
Views
1K
Replies
4
Views
1K
Replies
1
Views
1K
Replies
19
Views
965
Replies
1
Views
3K
Replies
12
Views
3K
Replies
1
Views
1K
Back
Top