Set boundary for least-square calculation

Hello,
When calculating least-squares we use the form Xw=y (where X is a matrix and y is a vector of appropriate dimensions).
This gives us an approximation, and it can happen that some resulting w will be such that its Xw<y.
Is there a way how to make every w big enough so that its Xw≥y?
And is it possible, at the same time, to make sure this Xw is smaller than some other given number?
Can MATLAB resolve this?
Thank you Best regards
hugo

 채택된 답변

Teja Muppirala
Teja Muppirala 2012년 4월 4일

0 개 추천

LSQLIN can do this:
W = rand(10,5);
y = rand(10,1);
someOtherGivenNumber = 1.3;
opts = optimset(optimset('lsqlin'),'LargeScale','off');
x = lsqlin(W,y,[-W; W] , [-y; 0*y+someOtherGivenNumber],[],[],[],[],[],opts)
If it successfully converges to a solution, then you can confirm that X*w >= y and X*w < someOtherGivenNumber (within some tolerances).

댓글 수: 6

Teja Muppirala
Teja Muppirala 2012년 4월 4일
LSQLIN is a function from the Optimization Toolbox
hugolove
hugolove 2012년 4월 4일
Hello Teja, thank you very much for your help. I am very new to MATLIB and do maths occasionally. I tried what you suggest.
When calculating least-squares we use the form Xw=y.
I have created this (10x5)Matrix X:
2 4 1 3 3
3 5 2 2 3
6 6 1 1 4
0 7 3 7 5
2 8 4 10 2
1 0 5 3 3
1 6 0 0 7
2 7 7 5 0
3 8 8 4 7
4 9 0 3 8
and this (10x1) vector y1.....y10:
105
45
36
78
20
60
30
20
79
94
then, when I run your code (for start without someOtherGivenNumber):
opts = optimset(optimset('lsqlin'),'LargeScale','off');
w = lsqlin(X,y,[-X; X] , [-y; 0*y],[],[],[],[],[],opts)
.....I get these w1 ...w5 numbers:
2.6923
5.3846
1.3462
4.0385
4.0385
then for a check, when I create a table by multiplication of these w numbers with transposed X, like:
w1*Xn1,m1..........w1*Xn1,m10
.............................
.............................
.............................
w5*Xn5,m1..........w5*Xn5,m10
and do sum of its columns I should get values same or bigger than y1.....y10:
105 45 36 78 20 60 30 20 79 94 (transposed vector of y)
But I did not get it. I got these numbers:
52.5 57.9 70 90.2 102 33.7 63.3 72.7 106 104
Do you know what have I done wrong please
hugo
Teja Muppirala
Teja Muppirala 2012년 4월 4일
Since you are not including the second constraint, the function call becomes:
w = lsqlin(X,y,-X , -y,[],[],[],[],[],opts)
In this case, I get a reasonable answer with your numbers.
See the help for LSQLIN to see how the constraints are formulated.
hugolove
hugolove 2012년 4월 5일
Dear Teja, you are right. I have set someOtherGivenNumber = 200 and after the multiplication I got:
105 85.8 151 118 180 99.7 42.6 20 98.8 169
so every of these numbers is bigger in comparison to its "column copy"
105 45 36 78 20 60 30 20 79 94
But now, can this someOtherGivenNumber be different for every Xw? So for example we would get sth. like:
105 70 140 115 180 99.7 42 20 98.8 155
hugolove
hugolove 2012년 4월 5일
well it is not very good example. off course if it was possible to set someOtherGivenNumber for every Xw all numbers would be shifted appropriately.
hugolove
hugolove 2012년 4월 6일
Hello Teja, although my question was not answered fully I thank you very much for your help and time, and for guiding me right direction. I mark your answer as the right one. From my last question I have made another post which can be found here:
http://www.mathworks.com/matlabcentral/answers/34740-how-to-use-lsqlin-to-set-different-upper-limit-for-each-xw
Again, thank you very much and have a nice weekend.
hugo

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Community Treasure Hunt

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

Start Hunting!

Translated by