Please help!! Need to constrain/force LSQNONLIN to pass through a given point e.g. the origin
Show older comments
Hello
I am struggling to implement constraints on nonlinear regression using lsqnonlin (or fmincon), where I need the fitted function to pass through a given point.
e.g. I have the simple function
function diff = fit_simp(x,X,Y)
A=x(1);
B=x(2);
diff = A*log(X+B) + A*log(1+B) - Y;
end
and the simple X and Y data attached (X and Y in columns 1 and 2 respectively of XY.txt). Then use lsqnonlin as follows:
X0=[-1,0];%Initial conditions
x=lsqnonlin(@fit_simp,X0,[],[],[],X,Y);
Y_new = x(1)*log(X+x(2))+x(1)*log(1+x(2));
plot(X,Y,'+r',X,Y_new,'b');
However the problem I have is that the function needs to pass through the (X,Y) point (1,0).
I have tried reading many help pages and tutorials to solve this issue however I haven't found any solution that applies to this situation. I have tried something similar with fmincon but cannot figure out how to implement the constraints.
So now I am devoid of ideas. I bought the Curve Fitting, Statistics and Optimization Toolboxes to specifically help me with this problem. Please help!!
Many thanks in advance, Chris
Accepted Answer
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!