# Least linear square fit of multiple measurements with functions sharing parameters

#### Sebastian.de

Dear All,

I would like to least square fit a number of measurements using several nonlinear functions with shared parameters (similar to the advanced fitting in Origin) using Mathematica.
Therefor I would be interested in an Algorithm like Gauss-Newton that fits several data-set to several functions (with shared parameters) "in parallel".
For example, I would like to fit the set of functions f1=a*exp(c1/x) ... fn=a*exp(cm/x) to a number of giving data-sets y1(x1,...,xm) ... yn(x1,...,xm). As indicated all "a" in f1...fn should have the same value while c1...cn differ.
Unfortunately, I can not find a suited algorithm on the Internet and I have a hard time adopting the algorithms fitting one function to one set of data.
I would appreciate any help, links or references that cover the given topic.

Thank you very much for your help!

Best regards,
Sebastian

#### Wallace

Re: Least linear square fit of multiple measurements with functions sharing parameter

I may have misunderstood your question, but the simplest thing I can think of is to consider the sum of all your functions $$\chi^2$$'s as a single number and minimise that over all the parameters in all of your functions. Then this reduces to a regular multi-dimensional minimisation.

This assumes that you are weighting all your functions equally in the fit, but you could add weights to the different $$\chi^2$$'s if that was relevant to your problem.

#### Sebastian.de

Re: Least linear square fit of multiple measurements with functions sharing parameter

Thank you very much for your reply. You didn't misunderstand my question. The approach you suggested seems perfectly fine to me. However, when I tried it I got stuck when generating the Jacobi-matrix.
I hardly have any experience in dealing with matrix calculation, so I am not sure if I ran into a big problem or if I am just to stupid to see the obvious.
The algorithms I found dealing with the least linear square problem generally proceeded in a way that minimizes the sum(f(x,parameters)-y)^2 (where f(x) is the fit function and y are the data points) by making up the Jacobi-matrix of (f(x,parameters)-y) with respect to the parameters. The square is then introduced by multiplying the Jacobi-matrix with its transpose.
If I understand your suggestion correct, I would end up minimizing a problem which looks like this: sum over i (sum(fi(xi,parameters-yi)^2). Having multiple sums of squares now instead of just one, I have not managed to figure out anything similar to the Jacobi-matrix used in the simpler problem. As a result, I was not able to use any of the algorithms I found.
I would be very grateful if you could point me towards any literature that deals with this problem in some detail. I am mildly optimistic that I would be able to write a script solving the problem with the help of a book that illustrates a applicable algorithm on an example.

Best regards,
Sebastian

#### Wallace

Re: Least linear square fit of multiple measurements with functions sharing parameter

There are multi-dimensional minimisation algorithms that do not require you to calculate the Jacobian. The one that springs to mind is the downhill simplex method, but there are probably others. I've used simplex a fair bit and it usually works well.http://www.gnu.org/software/gsl/manual/html_node/Multidimensional-Minimization.html" [Broken] is a good implementation of this algorithm in the Gnu Science Libraries

Last edited by a moderator:

#### gjanik

Re: Least linear square fit of multiple measurements with functions sharing parameter

I happen to be working on an almost identical problem, although in my case the time constants are common and the amplitudes are not. I took the data sets and time shifted and concatenated them so that they became one long data set. I then created an analytic fit function consisting of a sum of exponentials, each multiplied by two UnitStep functions which "turn it on" during the appropriate time period and turn it off for all other times. Each exponential is multiplied by zero for all times except when it's data is active. Finally, I used the FindFit function to fit the single data set to the single fit function. It would be nice if they had a more straightforward way to do this. A quick Google showed me that other math packages, like SigmaPlot, handle this sort of problem directly. I have attached sample code if you are interested.

#### Attachments

• 98.1 KB Views: 98

#### Sebastian.de

Re: Least linear square fit of multiple measurements with functions sharing parameter

Thank you very much to both of you. I think I have all the information I need now to fit the data.
Thanks again!

Best regards,
Sebastian

### Physics Forums Values

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving