MATLAB: How to perform non-linear curve fitting with restraints

curve fittinglsqcurvefitparameters

I want to fit data to a biexponential model, where all the parameters need to be positive. I've been using lsqcurvefit but I can't work out how to prevent it returning negative parameters.
start_point = rand(1, 4);
fun = @(params,time) params(1) .* (1-exp(-params(2) * time)) + params(3) .* (1-exp(-params(4) * time));
[Est,Error] = lsqcurvefit(fun,start_point,time,ydata)

Best Answer

Try this:
[Est,Error] = lsqcurvefit(fun,start_point,time,ydata,zeros(1,4),inf(1,4))