Curve fitting in Mathematica with FindMinimum function

Click For Summary
SUMMARY

This discussion focuses on using the FindMinimum function in Mathematica with the Levenberg-Marquardt method for curve fitting. The user seeks guidance on defining the residuals and the objective function while fitting a function f(x,a,b) to experimental data. Key insights include defining the residual as a vector of differences between observed and predicted values, and the realization that the objective function can be set to zero for the algorithm to function effectively. The provided example demonstrates successful implementation with specific parameter values.

PREREQUISITES
  • Familiarity with Mathematica programming language
  • Understanding of the Levenberg-Marquardt optimization method
  • Knowledge of curve fitting concepts and residuals
  • Experience with defining functions and using FindMinimum in Mathematica
NEXT STEPS
  • Explore the FindFit function in Mathematica for alternative curve fitting methods
  • Learn about defining and using residuals in optimization problems
  • Investigate advanced features of the Levenberg-Marquardt method in Mathematica
  • Study the implications of setting the objective function to zero in optimization
USEFUL FOR

Researchers, data analysts, and scientists who are utilizing Mathematica for curve fitting and optimization tasks, particularly those needing to implement the Levenberg-Marquardt method with the FindMinimum function.

grzesz
Messages
2
Reaction score
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
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}
 
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.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 19 ·
Replies
19
Views
3K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 6 ·
Replies
6
Views
6K