Re: find the maximum sum of a subset of a matrix

kjetil halvorsen (kjetil@caoba.entelnet.bo)
Tue, 27 Jan 1998 20:09:28 -0600


What about:

> x <- matrix(runif(16),4,4)
> o <- order(x)
> o.large <- o[12:16]
> x[o.large]
[1] 0.8130744 0.8957135 0.9207784 0.9550737
[5] 0.9582979
> x
[,1] [,2] [,3] [,4]
[1,] 0.7742870 0.2129502 0.3268367 0.95507370
[2,] 0.4685301 0.7034613 0.9582979 0.06388546
[3,] 0.1512756 0.7536401 0.8957135 0.92077843
[4,] 0.2235698 0.8130744 0.7388656 0.44840193
>

Kjetil.

haeberli wrote:
>
> I have a simple (simle looking?) problem for which I can't get an easy
> solution:
>
> I have a matrix like
>
> a11 a12 a13 a14....
> a21 a22 a23 a24....
> . . . .
> . . . .
>
> I want to determine those five elements in this matrix, which produce the
> maximum sum.
>
> Has somebody any idea how to do this?
>
> Christian Haeberli
> -------------------------------------------------------------------------------
> Christian Haeberli
> Institute for Meteorology and Geophysics
> Dept. for General Meteorology and Climatology
> Silbergasse 45/7
> A-1190 Wien
> Tel. +43 1 368 11 37 Fax +43 1 369 81 271
> email christian.haeberli@univie.ac.at
> -------------------------------------------------------------------------------