From: Frédéric Bergeron on 25 Jun 2010 14:13 Hi all, I posted a message earlier today, but I didn't get any response, so I'll simplify my problem to make it more accessible for everyone. You can find my previous thread at: http://www.mathworks.com/matlabcentral/newsreader/view_thread/285440. I search a way of adding a height difference constraint in a linear regression. I've already used regress() and lsqlin() and I think it might be possible using these function. I want to make a 2-dimensional linear regression (find the equation of the best-fit line) trought a set of data in a such way that the ratio between the total difference between the actual points over the line and the line, on the total difference between the points under the best-fit line and the line is equal to a previously defined ratio, R. For example, if I write my regression like this: %My regression %xdata and ydata: my data for the linear regression n=length(xdata); [a,b]=lsqlin([xdata ones(n,1)], ydata); %or [a,b]=regress(ydata, xdata ones(n,1)]); %y=a*x+b, the equation of the best fit line I want that after the regression, I found the coeffecient a and b that fit: R=variable defined before the regression; points_over=ydata>a*xdata+b; points_under=ydata<=a*xdata+b; sum(ydata(points_over))=R*sum(ydata(points_under)); %or the ratio R= sum(sum(ydata(points_over)))/sum(ydata(points_under)); Is there a way of defining this ratio R before the regression so that the regression take it as a constraint? Thanks for your help,
From: Frédéric Bergeron on 25 Jun 2010 14:31 > I want that after the regression, I found the coeffecient a and b that fit: > > R=variable defined before the regression; > points_over=ydata>a*xdata+b; > points_under=ydata<=a*xdata+b; > sum(ydata(points_over))=R*sum(ydata(points_under)); > %or the ratio R= sum(sum(ydata(points_over)))/sum(ydata(points_under)); Excuse me! The last part of my code is suppose to be the following to fit what I mean by the ratio R: yfit=a*xdata+b; sum( ydata(points_over) - yfit(points_over) )=... R*sum( yfit(points_under) - ydata(points_under) ); %R=(sum of height difference over) / (sum of height difference under)
|
Pages: 1 Prev: How do you understand accumarray? Next: Serial port -received data format problem |