Re: [R] Non-negative solution to an underdetermined linear system

2014-03-06 Thread Lyubomir Klyambarski
The unknown matrix is like this:
> x<-matrix(c("x11","x12","x13","x21","x22","x23","x31","x32","x33"),nrow=3,ncol=3,byrow=TRUE)
> x
     [,1]  [,2]  [,3] 
[1,] "x11" "x12" "x13"
[2,] "x21" "x22" "x23"
[3,] "x31" "x32" "x33"

This is my distance matrix.
> D<-matrix(c(1,5,10,5,2,6,10,6,8),nrow=3,ncol=3,byrow=TRUE)
> D
     [,1] [,2] [,3]
[1,]    1    5   10
[2,]    5    2    6
[3,]   10    6    8

I know the sums of each row and column of the X-matrix and also the sumproducts 
of each row and column (x11*D11+x12*D12+x13*D13). My task is to find matrix X 
with non-negative elements matching the known sums and sumproducts. I tried to 
solve this task as a system of linear equations like this: 
1.x11+1.x12+1.x13+0.x21+0.x22+0.x23+0.x31+0.x32+0.x33 = [known sum of row 1]
0.x11+0.x12+0.x13+1.x21+1.x22+1.x23+0.x31+0.x32+0.x33 = [known sum of row 2]

0.x11+0.x12+0.x13+0.x21+0.x22+0.x23+1.x31+1.x32+1.x33 = [known sum of row 3]

1.x11+0.x12+0.x13+1.x21+0.x22+0.x23+1.x31+0.x32+0.x33 = [known sum of column 1]

0.x11+1.x12+0.x13+0.x21+1.x22+0.x23+0.x31+1.x32+0.x33 = [known sum of column 2]

0.x11+0.x12+1.x13+0.x21+0.x22+1.x23+0.x31+0.x32+1.x33 = [known sum of column 3]

D11.x11+D12.x12+D13.x13+0.x21+0.x22+0.x23+0.x31+0.x32+0.x33 = [known sumproduct 
of row 1 X[1,] and D[1,]]
0.x11+0.x12+0.x13+D21.x21+D22.x22+D23.x23+0.x31+0.x32+0.x33 = [known sumproduct 
of row 2]

0.x11+0.x12+0.x13+0.x21+0.x22+0.x23+D31.x31+D32.x32+D33.x33 = [known sumproduct 
of row 3]

D11.x11+0.x12+0.x13+D21.x21+0.x22+0.x23+D31.x31+0.x32+0.x33 = [known sumproduct 
of column 1]

0.x11+D12.x12+0.x13+0.x21+D22.x22+0.x23+0.x31+D32.x32+0.x33 = [known sumproduct 
of column 2]

0.x11+0.x12+D13.x13+0.x21+0.x22+D23.x23+0.x31+0.x32+D33.x33 = [known sumproduct 
of column 3]

In this case is overdetermined system, but in my case is underdetermined 
(matrix 28x28). I think I could use the "lsei" function but with some 
modification in the source that it would return only positive x-es, but I don't 
know where to put this check.

Thanks in advance.
Best regards.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Non-negative solution to an underdetermined linear system

2014-03-04 Thread Berend Hasselman

On 04-03-2014, at 12:38, klq...@mail.bg wrote:

> I don't have any cost function to minimize. My task is to create the "best" 
> matrix, matching the row sums, the column sums, row sumproducts (with the 
> rows from another constant matrix) and also column sumproducts - it's a 
> transportation problem of finding OD matrix corresponding the total tonnage 
> and tonne-kilometres. Maybe the more suitable function would be "lsei", but 
> it retuns also negative values for some X-es. Do you have an idea where in 
> the code to put some verification for non-negative results?
> 

From the manual entry of lsei it seems that you should specify matrix G and 
vector h (inputs of lsei).

Berend


PS: Please do not post in HTML (see the posting guide).

> Thanks in advance.
> 
> Best Regards.
> 
> 
> - Цитат от Berend Hasselman (b...@xs4all.nl), на 27.02.2014 в 21:09 -
> 
>> 
>> On 27-02-2014, at 13:22, klq...@mail.bg wrote:
>> 
>>> 
>>> 
>>> 
>>> Dear R users,
>>> 
>>> 
>>> I have to find optimal solution of an underdetermined linear system, but
>>> only with positive variables. I tried the function from this post
>>> https://stat.ethz.ch/pipermail/r-help/2007-October/143408.html , but it's
>>> solution includes also negative values. 
>>> 
>>> 
>> 
>> Have a look at package limSolve. Maybe (and only maybe) function linp can be 
>> of use.
>> 
>> Berend
>> 
>>> Thanks in advance.
>>> 
>>> 
>>> Best Regards.
>>> 
>>> -
>>> 
>>> Майски празници на остров Лефкада, Гърция от 158 евро
>>> Безкрайните романтични пясъци съчетани с узо...
>>> Дати: 30/04/14 - 05/04/14
>>> http://www.arrivalsidi.com/%D0%BC%D0%B0%D0%B9%D1%81%D0%BA%D0%B8-%D0%BF%D1%80%D0%B0%D0%B7%D0%BD%D0%B8%D1%86%D0%B8/%D0%BC%D0%B0%D0%B9%D1%81%D0%BA%D0%B8-%D0%BF%D1%80%D0%B0%D0%B7%D0%BD%D0%B8%D1%86%D0%B8-%D0%B2-%D0%BB%D0%B5%D1%84%D0%BA%D0%B0%D0%B4%D0%B0
>>> [[alternative HTML version deleted]]
>>> 
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>> 
>> 
> 
> 
> 
> -
> Mail.BG: Безплатен e-mail адрес. Най-добрите характеристики на българския 
> пазар - 20 GB пощенска кутия, 1 GB прикрепен файл, безплатен POP3, мобилна 
> версия, SMS известяване и други.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Non-negative solution to an underdetermined linear system

2014-03-04 Thread klqmba



I don't have any cost function to minimize. My task is to create the "best"
matrix, matching the row sums, the column sums, row sumproducts (with the
rows from another constant matrix) and also column sumproducts - it's a
transportation problem of finding OD matrix corresponding the total tonnage
and tonne-kilometres. Maybe the more suitable function would be "lsei", but
it retuns also negative values for some X-es. Do you have an idea where in
the code to put some verification for non-negative results?


Thanks in advance.


Best Regards.


- Цитат от Berend Hasselman (b...@xs4all.nl), на 27.02.2014 в
21:09 -  
On 27-02-2014, at 13:22, klq...@mail.bg wrote:


Dear R users,


I have to find optimal solution of an underdetermined linear system, but
only with positive variables. I tried the function from this post
https://stat.ethz.ch/pipermail/r-help/2007-October/143408.html , but it's
solution includes also negative values. 


Have a look at package limSolve. Maybe (and only maybe) function linp can
be of use.


Berend


Thanks in advance.


Best Regards.


-


Майски празници на остров Лефкада,
Гърция от 158 евро
Безкрайните романтични пясъци съчетани
с узо...
Дати: 30/04/14 - 05/04/14
http://www.arrivalsidi.com/%D0%BC%D0%B0%D0%B9%D1%81%D0%BA%D0%B8-%D0%BF%D1%80%D0%B0%D0%B7%D0%BD%D0%B8%D1%86%D0%B8/%D0%BC%D0%B0%D0%B9%D1%81%D0%BA%D0%B8-%D0%BF%D1%80%D0%B0%D0%B7%D0%BD%D0%B8%D1%86%D0%B8-%D0%B2-%D0%BB%D0%B5%D1%84%D0%BA%D0%B0%D0%B4%D0%B0
[[alternative HTML version deleted]]


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




-
Mail.BG: Безплатен e-mail адрес. Най-добрите х
арактеристики на българския пазар - 20 GB 
пощенска кутия, 1 GB прикрепен файл, 
безплатен POP3, мобилна версия, SMS 
известяване и други. http://mail.bg
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Non-negative solution to an underdetermined linear system

2014-02-27 Thread Berend Hasselman

On 27-02-2014, at 13:22, klq...@mail.bg wrote:

> 
> 
> 
> Dear R users,
> 
> 
> I have to find optimal solution of an underdetermined linear system, but
> only with positive variables. I tried the function from this post
> https://stat.ethz.ch/pipermail/r-help/2007-October/143408.html , but it's
> solution includes also negative values. 
> 
> 

Have a look at package limSolve. Maybe (and only maybe) function linp can be of 
use.

Berend

> Thanks in advance.
> 
> 
> Best Regards.
> 
> -
> 
> Майски празници на остров Лефкада, Гърция от 158 евро
> Безкрайните романтични пясъци съчетани с узо...
> Дати: 30/04/14 - 05/04/14
> http://www.arrivalsidi.com/%D0%BC%D0%B0%D0%B9%D1%81%D0%BA%D0%B8-%D0%BF%D1%80%D0%B0%D0%B7%D0%BD%D0%B8%D1%86%D0%B8/%D0%BC%D0%B0%D0%B9%D1%81%D0%BA%D0%B8-%D0%BF%D1%80%D0%B0%D0%B7%D0%BD%D0%B8%D1%86%D0%B8-%D0%B2-%D0%BB%D0%B5%D1%84%D0%BA%D0%B0%D0%B4%D0%B0
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Non-negative solution to an underdetermined linear system

2014-02-27 Thread klqmba



Dear R users,


I have to find optimal solution of an underdetermined linear system, but
only with positive variables. I tried the function from this post
https://stat.ethz.ch/pipermail/r-help/2007-October/143408.html , but it's
solution includes also negative values. 


Thanks in advance.


Best Regards.

-

Майски празници на остров Лефкада, Гърция 
от 158 евро
Безкрайните романтични пясъци съчетани с 
узо...
Дати: 30/04/14 - 05/04/14
 
http://www.arrivalsidi.com/%D0%BC%D0%B0%D0%B9%D1%81%D0%BA%D0%B8-%D0%BF%D1%80%D0%B0%D0%B7%D0%BD%D0%B8%D1%86%D0%B8/%D0%BC%D0%B0%D0%B9%D1%81%D0%BA%D0%B8-%D0%BF%D1%80%D0%B0%D0%B7%D0%BD%D0%B8%D1%86%D0%B8-%D0%B2-%D0%BB%D0%B5%D1%84%D0%BA%D0%B0%D0%B4%D0%B0
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.