From: Yue Zhang on
There are 10 points, (x,y). I want to fit them to y=a*exp(-bx) and to find the value a and b. But a is between 0 and 1. How to fit this curve?
My code is
myfun = fittype('a*exp(-b*x)','independent','x');
fitopt = fitoptions('Method','NonLinearLeastSquares');
[pof,gof] = fit(x,y,myfun,fitopt);
But how to restrict a to be (0,1)? Many thanks in advance.
From: Greg Heath on
On Apr 1, 2:54 pm, "Yue Zhang" <yuezhang1...(a)gmail.com> wrote:
> There are 10 points, (x,y). I want to fit them to y=a*exp(-bx) and to find the value a and b. But a is between 0 and 1. How to fit this curve?
> My code is
> myfun = fittype('a*exp(-b*x)','independent','x');
> fitopt = fitoptions('Method','NonLinearLeastSquares');
> [pof,gof] = fit(x,y,myfun,fitopt);
> But how to restrict a to be (0,1)? Many thanks in advance.

I assume you have no nonpositive data
points y(i). Therefore, I deduce that
you are only concerned with preventing a > 1.
Try using a = exp(-c^2) .

Hope this helps.

Greg