# Fit with least squares, Levenberg–Marquardt algorithm

1. Oct 14, 2011

### TheDestroyer

Hello guys,

I need your help with understanding a fitting Algorithm, so that I could make it in a C++ program.

I have the following function:

g(f; f0, phi0, a, b) = phi0 + a ArcTan((f-f0)/b)

Which is a function of "f", frequency.

I would like to fit this function with the parameters f0, phi0, a and b.

http://en.wikipedia.org/wiki/Levenberg–Marquardt_algorithm

but I'm getting always lost where I don't understand how the things turn to Matrices. Please read what I did and explain how I can continue in a simple language, because all websites explaining this thingy are going complicated so fast.

I understand the idea of minimising squares of difference between my function and data points as follows

χ^2 = Ʃ (y_i - g(f_i; f0, phi0, a, b) )^2 // chi square, the error function to be minimised.

where y_i are the data point number i, that corresponds to the point f_i.

I calculated the derivatives of the function with respect to the parameters f0, phi0, a, b, lets call these derivatives g_f0, g_phi0, g_a, g_b. We set all these as a row matrix, and call it Jacobian (as far as I understood it).

J = {g_f0, g_phi0, g_a, g_b} //derivatives at the
δ = {f0, phi0, a, b}

and we multiply it with our parameters, after evaluating the derivatives at the initial points. Then we substitute this in χ^2:

χ^2 = Ʃ (y_i - g(f_i; f0, phi0, a, b) - J.δ)^2.

The way I understand it, I think there has to be a way to know what the values of delta this and next time has to become, so that the process is really "iterative".

The question is: how do we determine delta? and how do we determine the direction and magnitude of its update to reach the right function?

Thank you for any efforts

2. Oct 17, 2011

### TheDestroyer

Why hasn't no one answered? is the question bad formulated? or what exactly?

3. Dec 3, 2011

### yemallen

hi guys i need some to please help me with some worked examples on how to use levenberg-Marquardt Algorithm for non linear least squares optimization problems.

Most of the work you find on the internet are just descriptions of the algorithm, no one seems to be using it to solve nonlinear least square problems.

This is what i need; CAN SOMEONE PLEASE HELP ME TO USE THIS ALGORITHM TO SOLVE SOME NON LINEAR LEAST SQUARE PROBLEMS.

Thanks