How do I perform non-linear curve fitting with restraints?

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)

 Accepted Answer

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

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!