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:
Two curves fitting with two equations

Subject: Two curves fitting with two equations

From: Chong

Date: 28 Oct, 2012 15:18:08

Message: 1 of 9

Dear all,

I want to fit two curves with two equations which share several parameters. For example,
y1(x) = a1*f1(x)+b1*f2(x);
y2(x) = a1*f1(x)+b2*f2(x).

Does anyone know how to do this kind of fitting?

Thanks in advance.

Subject: Two curves fitting with two equations

From: Marc

Date: 28 Oct, 2012 18:49:08

Message: 2 of 9

"Chong " <wingser719@gmail.com> wrote in message <k6jibg$hd1$1@newscl01ah.mathworks.com>...
> Dear all,
>
> I want to fit two curves with two equations which share several parameters. For example,
> y1(x) = a1*f1(x)+b1*f2(x);
> y2(x) = a1*f1(x)+b2*f2(x).
>
> Does anyone know how to do this kind of fitting?
>
> Thanks in advance.

This is a non linear least squares problem. lscurvefit, lsqnonlin or nlinfit in the optimization and stats toolboxes will do the job.

I assume you have data for 'x' and are measuring y1 and y2 as responses. For most of these functions setting up y (and x for that matter) as vectors will be the way to go.
 
Check out the documentation for the optimization tool box or curve fitting toolbox.

Subject: Two curves fitting with two equations

From: Chong

Date: 29 Oct, 2012 05:45:08

Message: 3 of 9

Thank you for your reply. Maybe I didn't describe my question clearly.
Here y1 and y2 are equations I used for fitting two curves, which need to be input by myself. Since they share the parameter a1, I need to fit the two curves simultaneously.
My question is: In cftool, how to input two equations at the same time? Or any other methods to do this kind of fitting?
Thanks a lot.

"Marc" wrote in message <k6jun4$rd3$1@newscl01ah.mathworks.com>...
> "Chong " <wingser719@gmail.com> wrote in message <k6jibg$hd1$1@newscl01ah.mathworks.com>...
> > Dear all,
> >
> > I want to fit two curves with two equations which share several parameters. For example,
> > y1(x) = a1*f1(x)+b1*f2(x);
> > y2(x) = a1*f1(x)+b2*f2(x).
> >
> > Does anyone know how to do this kind of fitting?
> >
> > Thanks in advance.
>
> This is a non linear least squares problem. lscurvefit, lsqnonlin or nlinfit in the optimization and stats toolboxes will do the job.
>
> I assume you have data for 'x' and are measuring y1 and y2 as responses. For most of these functions setting up y (and x for that matter) as vectors will be the way to go.
>
> Check out the documentation for the optimization tool box or curve fitting toolbox.

Subject: Two curves fitting with two equations

From: Bruno Luong

Date: 29 Oct, 2012 07:28:08

Message: 4 of 9

"Chong " <wingser719@gmail.com> wrote in message <k6l554$3ej$1@newscl01ah.mathworks.com>...
> Thank you for your reply. Maybe I didn't describe my question clearly.
> Here y1 and y2 are equations I used for fitting two curves, which need to be input by myself. Since they share the parameter a1, I need to fit the two curves simultaneously.
> My question is: In cftool, how to input two equations at the same time? Or any other methods to do this kind of fitting?
> Thanks a lot.

For tool such as lsqnonlin, it does'nt matter if you have one, two or more curves. Just concatenate two function resultants in a long vector.

Bruno

Subject: Two curves fitting with two equations

From: Matt J

Date: 29 Oct, 2012 13:57:08

Message: 5 of 9

"Chong " <wingser719@gmail.com> wrote in message <k6jibg$hd1$1@newscl01ah.mathworks.com>...
> Dear all,
>
> I want to fit two curves with two equations which share several parameters. For example,
> y1(x) = a1*f1(x)+b1*f2(x);
> y2(x) = a1*f1(x)+b2*f2(x).
=============

I don't know why the others have concluded that this is a non-linear problem. Looks pretty linear to me, assuming a1,b1,b2 are the unknowns. If there are no errors in x, you can just use backslash, or otherwise, total least squares.

Subject: Two curves fitting with two equations

From: Marc

Date: 8 Dec, 2012 07:11:17

Message: 6 of 9

"Matt J" wrote in message <k6m1vk$bqm$1@newscl01ah.mathworks.com>...
> "Chong " <wingser719@gmail.com> wrote in message <k6jibg$hd1$1@newscl01ah.mathworks.com>...
> > Dear all,
> >
> > I want to fit two curves with two equations which share several parameters. For example,
> > y1(x) = a1*f1(x)+b1*f2(x);
> > y2(x) = a1*f1(x)+b2*f2(x).
> =============
>
> I don't know why the others have concluded that this is a non-linear problem. Looks pretty linear to me, assuming a1,b1,b2 are the unknowns. If there are no errors in x, you can just use backslash, or otherwise, total least squares.

I simply assumed that f1(x) and f2(x) was "highly" complex and non-linear. Hence pointing to the various non linear solvers.

I hope, albeit, maybe me being a bit optimistic, that if it was a simple linear problem, why would the OP bother with the f1(x) and f2(x)....

ie....

y(1) = a1*x+b1*x;
y(2) = a1*x+b2*x;

Subject: Two curves fitting with two equations

From: Matt J

Date: 8 Dec, 2012 11:28:06

Message: 7 of 9

"Marc" wrote in message <k9up6k$l5g$1@newscl01ah.mathworks.com>...
>
> > I don't know why the others have concluded that this is a non-linear problem. Looks pretty linear to me, assuming a1,b1,b2 are the unknowns. If there are no errors in x, you can just use backslash, or otherwise, total least squares.
>
> I simply assumed that f1(x) and f2(x) was "highly" complex and non-linear. Hence pointing to the various non linear solvers.
>
> I hope, albeit, maybe me being a bit optimistic, that if it was a simple linear problem, why would the OP bother with the f1(x) and f2(x)....
================

It is still a linear problem regardless of the form of f1(x) and f2(x). It is not the form of the dependence on x that matters as far as linearity is concerned. It is the dependence of y on the unknown parameters a1,b1,b2 and that dependence is linear. A linear equation solver can be used to find the unknowns here.

Subject: Two curves fitting with two equations

From: Marc

Date: 15 Dec, 2012 06:24:11

Message: 8 of 9

"Matt J" wrote in message <k9v886$8pa$1@newscl01ah.mathworks.com>...
> "Marc" wrote in message <k9up6k$l5g$1@newscl01ah.mathworks.com>...
> >
> > > I don't know why the others have concluded that this is a non-linear problem. Looks pretty linear to me, assuming a1,b1,b2 are the unknowns. If there are no errors in x, you can just use backslash, or otherwise, total least squares.
> >
> > I simply assumed that f1(x) and f2(x) was "highly" complex and non-linear. Hence pointing to the various non linear solvers.
> >
> > I hope, albeit, maybe me being a bit optimistic, that if it was a simple linear problem, why would the OP bother with the f1(x) and f2(x)....
> ================
>
> It is still a linear problem regardless of the form of f1(x) and f2(x). It is not the form of the dependence on x that matters as far as linearity is concerned. It is the dependence of y on the unknown parameters a1,b1,b2 and that dependence is linear. A linear equation solver can be used to find the unknowns here.

Since I have no idea what f1(x) and f2(x) look like and they are being used in both equations, I think we should both be able to agree that I can come up with forms of f1(x) and f2(x) which would make this a non linear problem.

Assuming all of the coefficients of f1(x) and f2(x) are known and not being solved for, I agree with you that this could be a very simple backslash problem.

Subject: Two curves fitting with two equations

From: Ali

Date: 2 Jan, 2013 21:53:10

Message: 9 of 9

"Marc" wrote in message <k6jun4$rd3$1@newscl01ah.mathworks.com>...
> "Chong " <wingser719@gmail.com> wrote in message <k6jibg$hd1$1@newscl01ah.mathworks.com>...
> > Dear all,
> >
> > I want to fit two curves with two equations which share several parameters. For example,
> > y1(x) = a1*f1(x)+b1*f2(x);
> > y2(x) = a1*f1(x)+b2*f2(x).
> >
> > Does anyone know how to do this kind of fitting?
> >
> > Thanks in advance.
>
> This is a non linear least squares problem. lscurvefit, lsqnonlin or nlinfit in the optimization and stats toolboxes will do the job.
>
> I assume you have data for 'x' and are measuring y1 and y2 as responses. For most of these functions setting up y (and x for that matter) as vectors will be the way to go.
>
> Check out the documentation for the optimization tool box or curve fitting toolbox.


Hey there
Sounds you can help me, I have got very similar and simpler case here
(y1-f1(x,t))^2+(y2-f2(x,t))^2=0 were x, y1 and y2 are known arrays(same size), and I just want to fit x and t.

unfortunately cftool cant help me, I cant import a second independent variable there (y1 and y2), I tried optimtool but its damn complicated! but if it is the last option can you give me some hints?

Thanks and advance!

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