"John D'Errico" <woodchips@rochester.rr.com> wrote in message <h402nt$man$1@fred.mathworks.com>...
> "Tazmusica " <tazmusica2@deletethis.gmail.com> wrote in message <h3vlju$s5f$1@fred.mathworks.com>...
> > I was wondering if anyone can help me to figure out how to add equality and inequality constraints to the linear parts of a separable least squares fit. I saw fminspleas is able to do it for the nonlinear fit parameters (using transformations from a constrained problem to an unconstrained one), but not for the linear fit parameters. Here is my code for the separable least squares fit. Thanks.
> >
> >
> > function[NLP,LP,res]=seplstsq(funlist,start_point,xdata,ydata,options)
> >
> >
> > function [sse,LP,res]=seplstsq_sse(NLP)
> > DM=zeros(length(ydata),length(funlist));
> >
> > for ii=1:length(funlist);
> > findx=funlist{ii};
> > term=findx(NLP,xdata);
> > DM(:,ii)=term(:);
> > end
> >
> > LP=DM\ydata;
> > res=DM*LPydata;
> > sse=sum(res.^2);
> >
> > end
> >
> > NLP=fminsearch(@seplstsq_sse,start_point,options);
> > [crap,LP,res]=seplstsq_sse(NLP);
> >
> > end
>
> Use lsqlin to solve the internal constrained linear least
> squares problem. It can use constraints. In fact if you
> have mixed LINEAR constraints that employ one or more
> of both classes of parameter, then you can define linear
> inequality or equality constraints for the internal lsqlin
> problem. The constant term in these internal linear
> constraints will be defined by the current value of the
> nonlinear parameters.
>
> The only thing you cannot do is to implement mixed
> nonlinear constraints that employ some of each class
> of parameter.
>
> John
John,
Thank you for your help. I am running into an issue where if I include bounds for my fits, Matlab is using 98% of my CPU and shows the "Busy" message indefinitely (for example when I give lower bounds as zero and no upper bounds). Yet when lb and ub are set to [], the fit on my test data is fine. For the test data, the linear parameter is >0, so I am not sure why it would behave this way. I am not sure what I am doing wrong, if my syntax is ok, and would appreciate any help. Here is the code:
function[NLP,LP,LPresnorm,LPres,lambda]=seplstsqcon(funlist,start_point,xdata,ydata,lb,ub,options)
function [LPresnorm,LPres,lambda]=seplstsqcon_sse(NLP)
DM=zeros(length(ydata),length(funlist));
for ii=1:length(funlist);
findx=funlist{ii};
term=findx(NLP,xdata);
DM(:,ii)=term(:);
end
[LP,LPresnorm,LPres,exitflag,output,lambda]=lsqlin(DM,ydata,[],[],[],[],lb,ub,lb,options);
end
NLP=fminsearch(@seplstsqcon_sse,start_point,options);
[crap,LP,LPresnorm,LPres,lambda]=seplstsqcon_sse(NLP);
end
