I need to write a Java program to generate a matrix with 3 rows and 5 columns such that: (1) The sum of each row is R. (2) The sums of columns are C1, C2, C3, C4, C5.
Satisfying any one of these conditions is pretty straightforward, e.g. to satisfy condition (1) I'll generate 5 random numbers between 0 and 1, calculate their sum, and then scale each of them up such that their sum is equal to R.
Or I can satisfy condition (2) by generating 3 random numbers and scaling them up so that their sum is C1 (or C2, C3, etc.)
But I have no idea how to satisfy both of these conditions together.
If it matters, all the numbers will be positive. They may or may not be integers.
Aucun commentaire:
Enregistrer un commentaire