MATLAB: Fitting equation with condition on 1 parameter

equationfit

I have to fit an equation over my data. Equation has two unknows parameters to be found i.e a and b…but if i deliberately want that the b value should lie betweem 0.2 and 2 and then find 'a' and 'b'…how can i do that???

Best Answer

Here is a simple script for fitting a Gaussian f(z) = a*exp(-b*z^2) using LSQCURVEFIT subject to bounds a>=0, 0<=b<=7. You should run it, study it, and adapt it to your needs.
f=@(p,z) p(1)*exp(-p(2)*z.^2);
x=linspace(0,2,10);
y=f([1,2],x)+rand(size(x))/10; %simulated data
p=lsqcurvefit( f, [.5,.5], x,y, [0,0],[inf,7]); %perform fit
plot(x,y,'*', x, f(p,x)) ;
You should also, of course, read "doc lsqcurvefit" to understand the input syntax and know what additional options you have.