Re: Creating an matrix of possible combinations



On Wed, 09 Aug 2006 19:11:02 -0700, Russ.Dilley wrote:

I am writing a program to process forces and moments. In general I have
3 forces and 3 moments. As a simplified example, using only forces, I
am given values F1, F2, and F3. These values can be positive or
negative. As a result I have 6 possible force values. I want to create
a table with all the possible force combinations:

| F1 F2 F3 |
| F1 F2 -F3 |
| F1 -F2 F3 |
| F1 -F2 -F3 |
| -F1 F2 F3 |
| -F1 F2 -F3 |
| -F1 -F2 F3 |
| -F1 -F2 -F3 |

[snip]

You could generate such a pattern by taking the
sign of the i+1,j+1 element of the table to be -1 if the j th
bit of i is set, and 1 otherwise. The magnitude is
F(j+1). Here 0<=i<2^n and 0<=j<number of forces
(well that will actually generate
( F1 F2 F3 )
( -F1 F2 F3 )
( F1 -F2 F3 )
( -F1 -F2 F3 )
....
If you really need the pattern shown you could determine
the sign based on the (numF-1-j)'th bit of i
)
Duncan


.


Quantcast