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:
Fitting the hyperbola Ax+Bxy+Cy+D=0 to experimental data

Subject: Fitting the hyperbola Ax+Bxy+Cy+D=0 to experimental data

From: David Heslop

Date: 14 Jan, 2010 08:39:03

Message: 1 of 12

Hi all,
I’m working with experimental data which is represented as a series of x and y values (both x and y are non-negative), which when plotted give a curved form. I know from theory that they should follow a hyperbolic curve of the form Ax+Bxy+Cy+D=0 and the question is how to determine A, B, C and D for the best-fit hyperbola through the data. Currently I’m using fminsearch to minimize the function:

function rs = myfun(coef,x,y)
rs=[x x.*y y ones(size(x))]*coef;
rs=sum(rs.^2);

Where coef is a 4 element column vector containing A, B, C and D. This seems to work okay sometimes, but of course is very sensitive to the initial choices of the coefficients and I really don’t know how robust such an approach is. Does anyone have any suggestions on a more suitable way to fit such a function?

Thanks, Dave

Subject: Fitting the hyperbola Ax+Bxy+Cy+D=0 to experimental data

From: Torsten Hennig

Date: 14 Jan, 2010 09:47:59

Message: 2 of 12

> Hi all,
> I’m working with experimental data which is
> represented as a series of x and y values (both x and
> y are non-negative), which when plotted give a curved
> form. I know from theory that they should follow a
> hyperbolic curve of the form Ax+Bxy+Cy+D=0 and the
> question is how to determine A, B, C and D for the
> best-fit hyperbola through the data. Currently
> I’m using fminsearch to minimize the function:
>
> function rs = myfun(coef,x,y)
> rs=[x x.*y y ones(size(x))]*coef;
> rs=sum(rs.^2);
>
> Where coef is a 4 element column vector containing A,
> B, C and D. This seems to work okay sometimes, but of
> course is very sensitive to the initial choices of
> the coefficients and I really don’t know how
> robust such an approach is. Does anyone have any
> suggestions on a more suitable way to fit such a
> function?
>
> Thanks, Dave

If M is the matrix with rows
[x_i; y_i*x_i; y_i ; 1], solve the eigenvalue problem
M^t * M * v = lambda * v
by using MATLAB's eig-function.
The eigenvector v (normalized such that ||v||=1)
corresponding to the smallest eigenvalue is the solution
to your problem (v=(A,B,C,D))

Best wishes
Torsten.

Subject: Fitting the hyperbola Ax+Bxy+Cy+D=0 to experimental data

From: Torsten Hennig

Date: 14 Jan, 2010 10:29:03

Message: 3 of 12

> Hi all,
> I’m working with experimental data which is
> represented as a series of x and y values (both x and
> y are non-negative), which when plotted give a curved
> form. I know from theory that they should follow a
> hyperbolic curve of the form Ax+Bxy+Cy+D=0 and the
> question is how to determine A, B, C and D for the
> best-fit hyperbola through the data. Currently
> I’m using fminsearch to minimize the function:
>
> function rs = myfun(coef,x,y)
> rs=[x x.*y y ones(size(x))]*coef;
> rs=sum(rs.^2);
>
> Where coef is a 4 element column vector containing A,
> B, C and D. This seems to work okay sometimes, but of
> course is very sensitive to the initial choices of
> the coefficients and I really don’t know how
> robust such an approach is. Does anyone have any
> suggestions on a more suitable way to fit such a
> function?
>
> Thanks, Dave

By the way:
For the function you are trying to minimize
(A,B,C,D) = (0,0,0,0) is always a solution -
and that's not what you want, I guess.

Best wishes
Torsten.

Subject: Fitting the hyperbola Ax+Bxy+Cy+D=0 to experimental data

From: David Heslop

Date: 14 Jan, 2010 10:48:03

Message: 4 of 12

Torsten Hennig <Torsten.Hennig@umsicht.fhg.de> wrote in message <232688810.68193.1263464973633.JavaMail.root@gallium.mathforum.org>...
> > Hi all,
> > I’m working with experimental data which is
> > represented as a series of x and y values (both x and
> > y are non-negative), which when plotted give a curved
> > form. I know from theory that they should follow a
> > hyperbolic curve of the form Ax+Bxy+Cy+D=0 and the
> > question is how to determine A, B, C and D for the
> > best-fit hyperbola through the data. Currently
> > I’m using fminsearch to minimize the function:
> >
> > function rs = myfun(coef,x,y)
> > rs=[x x.*y y ones(size(x))]*coef;
> > rs=sum(rs.^2);
> >
> > Where coef is a 4 element column vector containing A,
> > B, C and D. This seems to work okay sometimes, but of
> > course is very sensitive to the initial choices of
> > the coefficients and I really don’t know how
> > robust such an approach is. Does anyone have any
> > suggestions on a more suitable way to fit such a
> > function?
> >
> > Thanks, Dave
>
> By the way:
> For the function you are trying to minimize
> (A,B,C,D) = (0,0,0,0) is always a solution -
> and that's not what you want, I guess.
>
> Best wishes
> Torsten.

Hi Torsten
Your right, (A,B,C,D) = (0,0,0,0) isn't what I want. I tried the method you suggested and it works really nicely. One issue appears when I artificially add relatively small amounts of noise to the system (just scaled normally distributed random numbers). Then the fit can be a long way from the data, any suggestions?

thanks for your help, Dave

Subject: Fitting the hyperbola Ax+Bxy+Cy+D=0 to experimental data

From: Steven Lord

Date: 14 Jan, 2010 14:16:36

Message: 5 of 12


"David Heslop" <david_heslop@xyz.com> wrote in message
news:himl76$2ne$1@fred.mathworks.com...
> Hi all,
> I’m working with experimental data which is represented as a series
> of x and y values (both x and y are non-negative), which when plotted give
> a curved form. I know from theory that they should follow a hyperbolic
> curve of the form Ax+Bxy+Cy+D=0 and the question is how to determine A, B,
> C and D for the best-fit hyperbola through the data. Currently I’m
> using fminsearch to minimize the function:
>
> function rs = myfun(coef,x,y)
> rs=[x x.*y y ones(size(x))]*coef;
> rs=sum(rs.^2);
>
> Where coef is a 4 element column vector containing A, B, C and D. This
> seems to work okay sometimes, but of course is very sensitive to the
> initial choices of the coefficients and I really don’t know how
> robust such an approach is. Does anyone have any suggestions on a more
> suitable way to fit such a function?

I would try to transform this into a problem of the form M*coeffs = 0 and
use NULL.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: Fitting the hyperbola Ax+Bxy+Cy+D=0 to experimental data

From: David Heslop

Date: 14 Jan, 2010 15:00:22

Message: 6 of 12

"Steven Lord" <slord@mathworks.com> wrote in message <hin8vi$b3m$1@fred.mathworks.com>...
>
> "David Heslop" <david_heslop@xyz.com> wrote in message
> news:himl76$2ne$1@fred.mathworks.com...
> > Hi all,
> > I’m working with experimental data which is represented as a series
> > of x and y values (both x and y are non-negative), which when plotted give
> > a curved form. I know from theory that they should follow a hyperbolic
> > curve of the form Ax+Bxy+Cy+D=0 and the question is how to determine A, B,
> > C and D for the best-fit hyperbola through the data. Currently I’m
> > using fminsearch to minimize the function:
> >
> > function rs = myfun(coef,x,y)
> > rs=[x x.*y y ones(size(x))]*coef;
> > rs=sum(rs.^2);
> >
> > Where coef is a 4 element column vector containing A, B, C and D. This
> > seems to work okay sometimes, but of course is very sensitive to the
> > initial choices of the coefficients and I really don’t know how
> > robust such an approach is. Does anyone have any suggestions on a more
> > suitable way to fit such a function?
>
> I would try to transform this into a problem of the form M*coeffs = 0 and
> use NULL.
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>
Hi Steve,
thanks for the advice. NULL does work very well in the case of zero noise, but as soon as I add some noise to the data (even very small amounts) NULL returns an empty vector. Is there a way around this problem?
thanks, Dave

Subject: Fitting the hyperbola Ax+Bxy+Cy+D=0 to experimental data

From: Torsten Hennig

Date: 15 Jan, 2010 07:22:43

Message: 7 of 12

> Torsten Hennig <Torsten.Hennig@umsicht.fhg.de> wrote
> in message
> <232688810.68193.1263464973633.JavaMail.root@gallium.m
> athforum.org>...
> > > Hi all,
> > > I’m working with experimental data which is
> > > represented as a series of x and y values (both x
> and
> > > y are non-negative), which when plotted give a
> curved
> > > form. I know from theory that they should follow
> a
> > > hyperbolic curve of the form Ax+Bxy+Cy+D=0 and
> the
> > > question is how to determine A, B, C and D for
> the
> > > best-fit hyperbola through the data. Currently
> > > I’m using fminsearch to minimize the
> function:
> > >
> > > function rs = myfun(coef,x,y)
> > > rs=[x x.*y y ones(size(x))]*coef;
> > > rs=sum(rs.^2);
> > >
> > > Where coef is a 4 element column vector
> containing A,
> > > B, C and D. This seems to work okay sometimes,
> but of
> > > course is very sensitive to the initial choices
> of
> > > the coefficients and I really don’t know
> how
> > > robust such an approach is. Does anyone have any
> > > suggestions on a more suitable way to fit such a
> > > function?
> > >
> > > Thanks, Dave
> >
> > By the way:
> > For the function you are trying to minimize
> > (A,B,C,D) = (0,0,0,0) is always a solution -
> > and that's not what you want, I guess.
> >
> > Best wishes
> > Torsten.
>
> Hi Torsten
> Your right, (A,B,C,D) = (0,0,0,0) isn't what I want.
> I tried the method you suggested and it works really
> nicely. One issue appears when I artificially add
> relatively small amounts of noise to the system (just
> scaled normally distributed random numbers). Then the
> fit can be a long way from the data, any suggestions?
>
> thanks for your help, Dave

The estimated parameters should depend continuously
on the input data.
Maybe an error in your code ?

Best wishes
Torsten.

Subject: Fitting the hyperbola Ax+Bxy+Cy+D=0 to experimental data

From: David Heslop

Date: 15 Jan, 2010 10:18:03

Message: 8 of 12

Torsten Hennig <Torsten.Hennig@umsicht.fhg.de> wrote in message <1988820970.73186.1263540202253.JavaMail.root@gallium.mathforum.org>...
> > Torsten Hennig <Torsten.Hennig@umsicht.fhg.de> wrote
> > in message
> > <232688810.68193.1263464973633.JavaMail.root@gallium.m
> > athforum.org>...
> > > > Hi all,
> > > > I’m working with experimental data which is
> > > > represented as a series of x and y values (both x
> > and
> > > > y are non-negative), which when plotted give a
> > curved
> > > > form. I know from theory that they should follow
> > a
> > > > hyperbolic curve of the form Ax+Bxy+Cy+D=0 and
> > the
> > > > question is how to determine A, B, C and D for
> > the
> > > > best-fit hyperbola through the data. Currently
> > > > I’m using fminsearch to minimize the
> > function:
> > > >
> > > > function rs = myfun(coef,x,y)
> > > > rs=[x x.*y y ones(size(x))]*coef;
> > > > rs=sum(rs.^2);
> > > >
> > > > Where coef is a 4 element column vector
> > containing A,
> > > > B, C and D. This seems to work okay sometimes,
> > but of
> > > > course is very sensitive to the initial choices
> > of
> > > > the coefficients and I really don’t know
> > how
> > > > robust such an approach is. Does anyone have any
> > > > suggestions on a more suitable way to fit such a
> > > > function?
> > > >
> > > > Thanks, Dave
> > >
> > > By the way:
> > > For the function you are trying to minimize
> > > (A,B,C,D) = (0,0,0,0) is always a solution -
> > > and that's not what you want, I guess.
> > >
> > > Best wishes
> > > Torsten.
> >
> > Hi Torsten
> > Your right, (A,B,C,D) = (0,0,0,0) isn't what I want.
> > I tried the method you suggested and it works really
> > nicely. One issue appears when I artificially add
> > relatively small amounts of noise to the system (just
> > scaled normally distributed random numbers). Then the
> > fit can be a long way from the data, any suggestions?
> >
> > thanks for your help, Dave
>
> The estimated parameters should depend continuously
> on the input data.
> Maybe an error in your code ?
>
> Best wishes
> Torsten.

Hi Torsten,
I found the problem, I wasn't visualizing the result in a very sensible way. What I thought was mis-fit was simply the break between the two branches of the hyperbola. Do you have any ideas how I could constrain the fit so that only one branch is used to fit the data?
thanks again, Dave

Subject: Fitting the hyperbola Ax+Bxy+Cy+D=0 to experimental data

From: Arthur Livingstone

Date: 16 Feb, 2010 15:08:02

Message: 9 of 12

By the way, the hyperbolas Ax+Bxy+Cy+D=0 may be useful in factoring integers. In fact, let L=Bx+A, M=By+C, and L*M=N, where B>=2 is an arbitrary modulus, 0<=A<B and 0<=C<B. Then LM=B(Ax+Bxy+CY)+AC=N, whence (N-AC)/B=(Ax+Bxy+Cy)=-D.

Subject: Fitting the hyperbola Ax+Bxy+Cy+D=0 to experimental data

From: Christopher Beckett

Date: 21 Sep, 2010 11:17:04

Message: 10 of 12

"David Heslop" <david_heslop@xyz.com> wrote in message <hipfcr$fnb$1@fred.mathworks.com>...
> Torsten Hennig <Torsten.Hennig@umsicht.fhg.de> wrote in message <1988820970.73186.1263540202253.JavaMail.root@gallium.mathforum.org>...
> > > Torsten Hennig <Torsten.Hennig@umsicht.fhg.de> wrote
> > > in message
> > > <232688810.68193.1263464973633.JavaMail.root@gallium.m
> > > athforum.org>...
> > > > > Hi all,
> > > > > I’m working with experimental data which is
> > > > > represented as a series of x and y values (both x
> > > and
> > > > > y are non-negative), which when plotted give a
> > > curved
> > > > > form. I know from theory that they should follow
> > > a
> > > > > hyperbolic curve of the form Ax+Bxy+Cy+D=0 and
> > > the
> > > > > question is how to determine A, B, C and D for
> > > the
> > > > > best-fit hyperbola through the data. Currently
> > > > > I’m using fminsearch to minimize the
> > > function:
> > > > >
> > > > > function rs = myfun(coef,x,y)
> > > > > rs=[x x.*y y ones(size(x))]*coef;
> > > > > rs=sum(rs.^2);
> > > > >
> > > > > Where coef is a 4 element column vector
> > > containing A,
> > > > > B, C and D. This seems to work okay sometimes,
> > > but of
> > > > > course is very sensitive to the initial choices
> > > of
> > > > > the coefficients and I really don’t know
> > > how
> > > > > robust such an approach is. Does anyone have any
> > > > > suggestions on a more suitable way to fit such a
> > > > > function?
> > > > >
> > > > > Thanks, Dave
> > > >
> > > > By the way:
> > > > For the function you are trying to minimize
> > > > (A,B,C,D) = (0,0,0,0) is always a solution -
> > > > and that's not what you want, I guess.
> > > >
> > > > Best wishes
> > > > Torsten.
> > >
> > > Hi Torsten
> > > Your right, (A,B,C,D) = (0,0,0,0) isn't what I want.
> > > I tried the method you suggested and it works really
> > > nicely. One issue appears when I artificially add
> > > relatively small amounts of noise to the system (just
> > > scaled normally distributed random numbers). Then the
> > > fit can be a long way from the data, any suggestions?
> > >
> > > thanks for your help, Dave
> >
> > The estimated parameters should depend continuously
> > on the input data.
> > Maybe an error in your code ?
> >
> > Best wishes
> > Torsten.
>
> Hi Torsten,
> I found the problem, I wasn't visualizing the result in a very sensible way. What I thought was mis-fit was simply the break between the two branches of the hyperbola. Do you have any ideas how I could constrain the fit so that only one branch is used to fit the data?
> thanks again, Dave

Dear Torsten,

I have a similar problem fitting a hyperbolic fit to my data, but have found your first post quite useful. I have a few questions, however:

Firstly, when you said "M^t*M*v", did you mean "M*M^t*v" - I find that the former results in a 1x1 matrix and so only a single value in the eigenvector.

Secondly, when you say "The eigenvector v (normalized such that ||v||=1)
corresponding to the smallest eigenvalue is the solution
to your problem (v=(A,B,C,D))", are you referring to the smallest of all of the eigenvalues generated by using the "eig" function, or the smallest in each itteration over the datapoints? Say if I have 10 data points, the use of the M*M^t matrix will result in 40 eigenvalues (4 for each datapoint pair with 10 datapoint pairs) - do I use the eigenvector coresponding to the smallest of all 40 eigenvalues? If the smallest eigenvalue is zero, is the use of the corresponding eigenvector still valid? I'm assuming that "the smallest" also refers to the smallest absolute value.

Lastly, the "eig" function seems to already normalise the eigenvectors, so I have left that stage out.

Thank you very much for any help you can provide,

Kind regards,

Chris

Subject: Fitting the hyperbola Ax+Bxy+Cy+D=0 to experimental data

From: Torsten Hennig

Date: 22 Sep, 2010 16:26:15

Message: 11 of 12

>
> Dear Torsten,
>
> I have a similar problem fitting a hyperbolic fit to
> my data, but have found your first post quite useful.
> I have a few questions, however:
>
> Firstly, when you said "M^t*M*v", did you mean
> "M*M^t*v" - I find that the former results in a 1x1
> matrix and so only a single value in the eigenvector.
>

If n is the number of data points (x_i,y_i),
M is a (nx4) - matrix.
Thus M^t*M is a (4x4) - matrix.

> Secondly, when you say "The eigenvector v (normalized
> such that ||v||=1)
> corresponding to the smallest eigenvalue is the
> solution
> to your problem (v=(A,B,C,D))", are you referring to
> the smallest of all of the eigenvalues generated by
> using the "eig" function, or the smallest in each
> itteration over the datapoints? Say if I have 10 data
> points, the use of the M*M^t matrix will result in 40
> eigenvalues (4 for each datapoint pair with 10
> datapoint pairs) - do I use the eigenvector
> coresponding to the smallest of all 40 eigenvalues?
> If the smallest eigenvalue is zero, is the use of the
> corresponding eigenvector still valid? I'm assuming
> that "the smallest" also refers to the smallest
> absolute value.
>

Since M^t*M is real and symmetric, you will get 4 real eigenvalues.
The eigenvector v (normalized such that norm(v)=1) corresponding to the smallest eigenvalue is the
solution to your problem ((v=(A,B,C,D)).

> Lastly, the "eig" function seems to already normalise
> the eigenvectors, so I have left that stage out.
>
> Thank you very much for any help you can provide,
>
> Kind regards,
>
> Chris

Best wishes
Torsten.

Subject: Fitting the hyperbola Ax+Bxy+Cy+D=0 to experimental data

From: Christopher Beckett

Date: 23 Sep, 2010 08:30:20

Message: 12 of 12

Torsten Hennig <Torsten.Hennig@umsicht.fhg.de> wrote in message <1493857119.95669.1285172826009.JavaMail.root@gallium.mathforum.org>...
> >
> > Dear Torsten,
> >
> > I have a similar problem fitting a hyperbolic fit to
> > my data, but have found your first post quite useful.
> > I have a few questions, however:
> >
> > Firstly, when you said "M^t*M*v", did you mean
> > "M*M^t*v" - I find that the former results in a 1x1
> > matrix and so only a single value in the eigenvector.
> >
>
> If n is the number of data points (x_i,y_i),
> M is a (nx4) - matrix.
> Thus M^t*M is a (4x4) - matrix.
>
> > Secondly, when you say "The eigenvector v (normalized
> > such that ||v||=1)
> > corresponding to the smallest eigenvalue is the
> > solution
> > to your problem (v=(A,B,C,D))", are you referring to
> > the smallest of all of the eigenvalues generated by
> > using the "eig" function, or the smallest in each
> > itteration over the datapoints? Say if I have 10 data
> > points, the use of the M*M^t matrix will result in 40
> > eigenvalues (4 for each datapoint pair with 10
> > datapoint pairs) - do I use the eigenvector
> > coresponding to the smallest of all 40 eigenvalues?
> > If the smallest eigenvalue is zero, is the use of the
> > corresponding eigenvector still valid? I'm assuming
> > that "the smallest" also refers to the smallest
> > absolute value.
> >
>
> Since M^t*M is real and symmetric, you will get 4 real eigenvalues.
> The eigenvector v (normalized such that norm(v)=1) corresponding to the smallest eigenvalue is the
> solution to your problem ((v=(A,B,C,D)).
>
> > Lastly, the "eig" function seems to already normalise
> > the eigenvectors, so I have left that stage out.
> >
> > Thank you very much for any help you can provide,
> >
> > Kind regards,
> >
> > Chris
>
> Best wishes
> Torsten.

Dear Torsten,

Thank you for clearing that up - my mistake had been to take M_i = [x_i, x_i*y_i, y_i, 1] and then use that in the M'*M*v = lambda * v, looping ofer the data point pairs and then selecting the smallest resulting eigenvalue, rather than have all of the data in the [n x 4] M matrix initially. It now seems to work perfectly.

Many thanks and best wishes,

Chris

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