Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
data fitting for 2 data sets and functions

Subject: data fitting for 2 data sets and functions

From: Mohammad Monfared

Date: 20 Feb, 2010 19:36:02

Message: 1 of 8

Hi everybody,

I'd like to do a curve-fitting job for two sets of function and data, simultaneously. That is: functions are: F1(x,t,u,z) & F2(x,u,z,w) ['x' is the only argument and the others are parameters to be found] and for each function we are provided with data sets: Xs and Ys. I'm going to find the values of the parameters to best fit the two data sets in the same time.
Is there any appropriate function in matlab or its toolboxes for this purpose or does any one know any trick?

thanks,

Subject: data fitting for 2 data sets and functions

From: Sadik

Date: 20 Feb, 2010 23:17:03

Message: 2 of 8

Hello Mohammad,

Have you looked at the Levenberg-Marquardt method? It does nonlinear least squares fitting. There is a function on Mathworks File Exchange [FEX] website:

http://www.mathworks.com/matlabcentral/fileexchange/16063-lmfsolve-m-levenberg-marquardt-fletcher-algorithm-for-nonlinear-least-squares-problems

I have also seen the same method being mentioned in the optimization toolbox but I have never used it.

As for the problem of fitting the two functions simultaneously, unfortunately I don't have a good idea...

Best.



"Mohammad Monfared" <gohardoust@gmail.com> wrote in message <hlpdj2$6nv$1@fred.mathworks.com>...
> Hi everybody,
>
> I'd like to do a curve-fitting job for two sets of function and data, simultaneously. That is: functions are: F1(x,t,u,z) & F2(x,u,z,w) ['x' is the only argument and the others are parameters to be found] and for each function we are provided with data sets: Xs and Ys. I'm going to find the values of the parameters to best fit the two data sets in the same time.
> Is there any appropriate function in matlab or its toolboxes for this purpose or does any one know any trick?
>
> thanks,

Subject: data fitting for 2 data sets and functions

From: Mohammad Monfared

Date: 21 Feb, 2010 20:31:05

Message: 3 of 8

"Sadik " <sadik.hava@gmail.com> wrote in message <hlpqhf$d1b$1@fred.mathworks.com>...
> Hello Mohammad,
>
> Have you looked at the Levenberg-Marquardt method? It does nonlinear least squares fitting. There is a function on Mathworks File Exchange [FEX] website:
>
> http://www.mathworks.com/matlabcentral/fileexchange/16063-lmfsolve-m-levenberg-marquardt-fletcher-algorithm-for-nonlinear-least-squares-problems
>
> I have also seen the same method being mentioned in the optimization toolbox but I have never used it.
>
> As for the problem of fitting the two functions simultaneously, unfortunately I don't have a good idea...
>
> Best.
>
>
thanks Sadik for your reply,

I've tried to solve this problem by minimizing the sum of norm2 values of the residual of data and each function, I mean the following function :

norm(F1(X1) - Y1) + norm(F2(X2) - Y2)

with 'fmincon' function. But I couldn't get any acceptable result. in fact no result when just fitting one function to the data set! while this is an easy job for 'lsqcurvefit' function. I wonder how 'lsqcurvefit' minimize the norm values?

anyway thanks again.

Subject: data fitting for 2 data sets and functions

From: Sadik

Date: 21 Feb, 2010 21:04:04

Message: 4 of 8

From the documentation, it seems that lsqcurvefit is minimizing the sum of squared errors.

Actually, if I were you, I would check two things:

1. Did I program the optimization correctly?
2. Why do you use fmincon? You don't have any constraints, right? So maybe you should use fminunc.

Best.



<hls569$nkb$1@fred.mathworks.com>...
> "Sadik " <sadik.hava@gmail.com> wrote in message <hlpqhf$d1b$1@fred.mathworks.com>...
> > Hello Mohammad,
> >
> > Have you looked at the Levenberg-Marquardt method? It does nonlinear least squares fitting. There is a function on Mathworks File Exchange [FEX] website:
> >
> > http://www.mathworks.com/matlabcentral/fileexchange/16063-lmfsolve-m-levenberg-marquardt-fletcher-algorithm-for-nonlinear-least-squares-problems
> >
> > I have also seen the same method being mentioned in the optimization toolbox but I have never used it.
> >
> > As for the problem of fitting the two functions simultaneously, unfortunately I don't have a good idea...
> >
> > Best.
> >
> >
> thanks Sadik for your reply,
>
> I've tried to solve this problem by minimizing the sum of norm2 values of the residual of data and each function, I mean the following function :
>
> norm(F1(X1) - Y1) + norm(F2(X2) - Y2)
>
> with 'fmincon' function. But I couldn't get any acceptable result. in fact no result when just fitting one function to the data set! while this is an easy job for 'lsqcurvefit' function. I wonder how 'lsqcurvefit' minimize the norm values?
>
> anyway thanks again.

Subject: data fitting for 2 data sets and functions

From: Mohammad Monfared

Date: 5 Mar, 2010 20:44:23

Message: 5 of 8

You are right, the function to be minimized would be:

   norm(F1(X1) - Y1)^2 + norm(F2(X2) - Y2)^2

and yes my parameters are constrained then I should use 'fmincon' . In addition to my previous attempt, now I've provided my function with the gradient, but still no acceptable answer.

"Sadik " <sadik.hava@gmail.com> wrote in message <hls744$gd7$1@fred.mathworks.com>...
> From the documentation, it seems that lsqcurvefit is minimizing the sum of squared errors.
>
> Actually, if I were you, I would check two things:
>
> 1. Did I program the optimization correctly?
> 2. Why do you use fmincon? You don't have any constraints, right? So maybe you should use fminunc.
>
> Best.
>

Subject: data fitting for 2 data sets and functions

From: Seyoum

Date: 30 Sep, 2010 23:39:19

Message: 6 of 8

"Mohammad Monfared" <gohardoust@gmail.com> wrote in message <hlpdj2$6nv$1@fred.mathworks.com>...
> Hi everybody,
>
> I'd like to do a curve-fitting job for two sets of function and data, simultaneously. That is: functions are: F1(x,t,u,z) & F2(x,u,z,w) ['x' is the only argument and the others are parameters to be found] and for each function we are provided with data sets: Xs and Ys. I'm going to find the values of the parameters to best fit the two data sets in the same time.
> Is there any appropriate function in matlab or its toolboxes for this purpose or does any one know any trick?
>
> thanks,

Subject: data fitting for 2 data sets and functions

From: Seyoum

Date: 30 Sep, 2010 23:44:06

Message: 7 of 8

"Mohammad Monfared" <gohardoust@gmail.com> wrote in message <hlpdj2$6nv$1@fred.mathworks.com>...
> Hi everybody,
>
> I'd like to do a curve-fitting job for two sets of function and data, simultaneously. That is: functions are: F1(x,t,u,z) & F2(x,u,z,w) ['x' is the only argument and the others are parameters to be found] and for each function we are provided with data sets: Xs and Ys. I'm going to find the values of the parameters to best fit the two data sets in the same time.
> Is there any appropriate function in matlab or its toolboxes for this purpose or does any one know any trick?
>
> thanks,

Have you found answer to this issue as I also faced with the same problem: I have one data set (x,y) to be fitted to two independent functions, each function has parameters to be solved for.
Thanks

Subject: data fitting for 2 data sets and functions

From: Mohammad Monfared

Date: 11 Oct, 2010 12:07:03

Message: 8 of 8

"Seyoum " <sgebremariam@wsu.edu> wrote in message <i837c6$1mt$1@fred.mathworks.com>...
> "Mohammad Monfared" <gohardoust@gmail.com> wrote in message <hlpdj2$6nv$1@fred.mathworks.com>...
> > Hi everybody,
> >
> > I'd like to do a curve-fitting job for two sets of function and data, simultaneously. That is: functions are: F1(x,t,u,z) & F2(x,u,z,w) ['x' is the only argument and the others are parameters to be found] and for each function we are provided with data sets: Xs and Ys. I'm going to find the values of the parameters to best fit the two data sets in the same time.
> > Is there any appropriate function in matlab or its toolboxes for this purpose or does any one know any trick?
> >
> > thanks,
>
> Have you found answer to this issue as I also faced with the same problem: I have one data set (x,y) to be fitted to two independent functions, each function has parameters to be solved for.
> Thanks

Yes, I wrote a unique function (to be minimized) which its inputs were: a parameter vector( containing parameters of two functions ) and the available data sets. It calculates the value: norm(F1(X1) - Y1)^2 + norm(F2(X2) - Y2)^2, or in your case : norm(F1(X1) - Y1)^2 + norm(F2(X1) - Y1)^2 . then this function was minimized by "fmincon" function, but since my data was so noisy I found Genetic Algorithm more convenient for the purpose of minimization.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us