Thread Subject:
curve fitting, relationship between fitted parameters

Subject: curve fitting, relationship between fitted parameters

From: Tina

Date: 3 Aug, 2012 13:30:32

Message: 1 of 7

Hello,

I'm basically trying to fit data to the curve
a*exp(b)+(1-a)*exp(c)

How can I set the condition b<c for matlab to include into the fitting procedure?

Thanks in advance,
Tina

Subject: curve fitting, relationship between fitted parameters

From: Matt J

Date: 3 Aug, 2012 13:37:12

Message: 2 of 7

"Tina" wrote in message <jvgjpo$pd0$1@newscl01ah.mathworks.com>...
> Hello,
>
> I'm basically trying to fit data to the curve
> a*exp(b)+(1-a)*exp(c)
>
> How can I set the condition b<c for matlab to include into the fitting procedure?

Maybe reparametrize as

a*exp(b)+(1-a)*exp(b+exp(d))

where we have made the change of variables c=b+exp(d)

Subject: curve fitting, relationship between fitted parameters

From: Tina

Date: 3 Aug, 2012 13:51:13

Message: 3 of 7

"Matt J" wrote in message <jvgk68$r0h$1@newscl01ah.mathworks.com>...
> "Tina" wrote in message <jvgjpo$pd0$1@newscl01ah.mathworks.com>...
> > Hello,
> >
> > I'm basically trying to fit data to the curve
> > a*exp(b)+(1-a)*exp(c)
> >
> > How can I set the condition b<c for matlab to include into the fitting procedure?
>
> Maybe reparametrize as
>
> a*exp(b)+(1-a)*exp(b+exp(d))
>
> where we have made the change of variables c=b+exp(d)

Hi Matt,

Thank you for your help, this is a smart and simple idea!

My equation is in reality a bit more complicated than the one above:

sqrt((M0^2)*((A^2)*(exp(-2*x/B))+2*A*(1-A).*exp(-x/C).*exp(-x/B).*cos(f*x*(10^(-3))*2*pi)+((1-A)^2)*exp(-2*x/C)))

where M0, A, B, C, f are parameters, x is the data.

So I should just substitute exp(1/C) with exp(1/B+1/C)?

Subject: curve fitting, relationship between fitted parameters

From: Matt J

Date: 3 Aug, 2012 13:56:12

Message: 4 of 7

"Matt J" wrote in message <jvgk68$r0h$1@newscl01ah.mathworks.com>...
> "Tina" wrote in message <jvgjpo$pd0$1@newscl01ah.mathworks.com>...
> > Hello,
> >
> > I'm basically trying to fit data to the curve
> > a*exp(b)+(1-a)*exp(c)
> >
> > How can I set the condition b<c for matlab to include into the fitting procedure?
>
> Maybe reparametrize as
>
> a*exp(b)+(1-a)*exp(b+exp(d))
>
> where we have made the change of variables c=b+exp(d)
===============

Better: exp(b+exp(d)) can also be parametrized exp(b)+exp(d) leading to

exp(b)-a*exp(d)

However, since you have no bounds on b,c and hence also not on d, you can't really try to force the values exp(b) and exp(d) to be strictly positive. At best you can force them to be non-negative by reparametrizing as

b^2+a*d^2

Subject: curve fitting, relationship between fitted parameters

From: Tina

Date: 3 Aug, 2012 15:01:22

Message: 5 of 7

"Matt J" wrote in message <jvgl9s$2mq$1@newscl01ah.mathworks.com>...
> "Matt J" wrote in message <jvgk68$r0h$1@newscl01ah.mathworks.com>...
> > "Tina" wrote in message <jvgjpo$pd0$1@newscl01ah.mathworks.com>...
> > > Hello,
> > >
> > > I'm basically trying to fit data to the curve
> > > a*exp(b)+(1-a)*exp(c)
> > >
> > > How can I set the condition b<c for matlab to include into the fitting procedure?
> >
> > Maybe reparametrize as
> >
> > a*exp(b)+(1-a)*exp(b+exp(d))
> >
> > where we have made the change of variables c=b+exp(d)
> ===============
>
> Better: exp(b+exp(d)) can also be parametrized exp(b)+exp(d) leading to
>
> exp(b)-a*exp(d)
>
> However, since you have no bounds on b,c and hence also not on d, you can't really try to force the values exp(b) and exp(d) to be strictly positive. At best you can force them to be non-negative by reparametrizing as
>
> b^2+a*d^2

Hi Matt,

I have parameter bounds.
Like 'Upper',[2*max(FitVektorY),1,200,200,1600] and something similar for lower.

I tried reparametrizing, but the fit now is even worse.

Isn't there a way to just tell matlab to include the condition b>c in the fitting procedure?

Subject: curve fitting, relationship between fitted parameters

From: Matt J

Date: 3 Aug, 2012 15:15:10

Message: 6 of 7

"Tina" wrote in message <jvgp42$irt$1@newscl01ah.mathworks.com>...
>
>
> Isn't there a way to just tell matlab to include the condition b>c in the fitting procedure?
=============

It depends what toolboxes you have. You can specify things like b>=c (non-strict equality) in FMINCON for example

Subject: curve fitting, relationship between fitted parameters

From: Matt J

Date: 3 Aug, 2012 16:10:32

Message: 7 of 7

"Tina" wrote in message <jvgl0g$1cd$1@newscl01ah.mathworks.com>...
>
> My equation is in reality a bit more complicated than the one above:
>
> sqrt((M0^2)*((A^2)*(exp(-2*x/B))+2*A*(1-A).*exp(-x/C).*exp(-x/B).*cos(f*x*(10^(-3))*2*pi)+((1-A)^2)*exp(-2*x/C)))
>
> where M0, A, B, C, f are parameters, x is the data.
============

BTW, you will have to get rid of the sqrt() if you are fitting with any algorithm that relies on derivatives. The function sqrt(r) is non-differentiable at r=0, which is bad for you because r=0 is where you want your residuals to be. Maybe instead of fitting
y=g(x)
you can instead fit y^2=g^2(x)



> So I should just substitute exp(1/C) with exp(1/B+1/C)?
===========

Don't know why you'd propose that. Which is supposed to be larger in this case, B or C? In any case exp(1/B+1/C) can be either greater or larger than exp(1/C) depending on the signs of B and C.

Also, it might be better to parametrize as exp(B*x) and exp(C*x) instead of
exp(-2*x/B) and exp(-2*x/C) because you have undefined beahvior at B=C=0.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
curve fitting rela... Tina 3 Aug, 2012 09:34:17
rssFeed for this Thread

Contact us