1

I am trying to find an algorithm to solve the current problem. I have multiple unknown variables (F1,F2,F3, ... Fx) and (R1,R2,R3 ... Rx) and multiple equations like this:

F1 + R1 = a
F1 + R2 = a
F2 + R1 = b
F3 + R2 = b
F2 + R3 = c
F3 + R4 = c

where a, b and c are known numbers. I am trying to find all equal variables in such equations. For example in the above equation I could see that F2 and F3 are equal and R3 and R4 are equal.

First equations tells us that R1 and R2 are equal, and second tells us that F2 and F3 are equal, while the third tells us that R3 and R4 are equal.

For a more complex scenario, is there any known algorithm that can find all equal (F and R) variables????

(I will edit the question if it is not clear enough)

Thanks

koms
  • 11
  • 3
  • By "more complex scenario", do you mean a situation where there are more than two unknown variables in one equation? – Acccumulation Dec 05 '17 at 18:58
  • No, all equations has only two variables. I am trying to find all equal F variables and all equal R variables. The more complex scenario means hundreds of equations. – koms Dec 05 '17 at 19:26
  • How many equations, how many variables? (in your example you got more variables then equations; it's an important fact) – sascha Dec 05 '17 at 21:06
  • I might get more variables than equations, but I know for sure the equations can not be solved. There are no multiple equations containing the same set of variables. I can never find the value of Fx or Rx. But I can find if Fx is eqal to Fy and Fz for example, which is what I am trying to achieve. The number of equations and variables depends on how long I run some experiment and the experiment conditions. For the controlled testing environment, I have 128 Forward (F) variables and 128 Reverse (R) variables and 2200 equations. – koms Dec 06 '17 at 17:03
  • If there is no solution, what's the objective then? It sounds you got two components: maximize the number of equal variables and maximize the enforced constraints. These are in general conflicting and there needs to be some model on how to control this. (example: no constraint fulfilled: set all variables to 0) – sascha Dec 06 '17 at 17:47
  • @sascha, the reason for this is that I know in my experiments that I will always see two variables and I am interested in knowing the result. To explain, if you took the above equations and assume these are what I saw during the measurement phase, and then later I saw the variables F2,R4 combination (even though I have not seen this combination before, I would know the result is c). The equations are given, but later I will only see variables and I need to know the sum of these variables. – koms Dec 07 '17 at 17:07

2 Answers2

0

Here's a hint: you have defined a system of linear equations with 7 variables and 6 equations. Here's a crude matrix/vector notation:

 1 0 0 1 0 0 0     F1     a
 1 0 0 0 1 0 0     F2     a
 0 1 0 1 0 0 0  *  F3  =  b
 0 0 1 0 1 0 0     R1     b
 0 1 0 0 0 1 0     R2     c
 0 0 1 0 0 0 1     R3     c
                   R4

If you do the Gaussian elimination manually, you can see that e.g. first row minus the second row results in

 (0 0 0 1 -1 0 0) * (F1 F2 F3 R1 R2 R3 R4)^T = a - a
                                     R1 - R2 = 0
                                          R1 = R2

Which implies that R1 and R2 are what you call equivalent. There are many different methods to solve the system or interpret the results. Maybe you will find this thread useful: Is there a standard solution for Gauss elimination in Python?

Pavel
  • 7,436
  • 2
  • 29
  • 42
  • In sympy, there's `rref()` that returns the row echelon form. If any row contains only two nonzero entries, and one of them is -1 and not in the augmented column, then that represents two equivalent variables. – Acccumulation Dec 05 '17 at 19:03
0

For the general situation, row echelon is probably the way to go. If every equation has only two variables, then you can consider each variable to be in a partition. Every time two variables appear in an equation together, their partitions are joined. So to begin with each variable is in its own partition. After the first equation, there a partition that contains F1 and R1. After the second equation, that partition is replaced by a partition that contain F1, R1 and R2. You should have the variables in some sort of order, and when two partitions are joined, put all the variables except the first one in terms of the first one (it doesn't really matter how you order the variables, you just need some way of deciding which is the "first"). So for instance, after the first equation, you have R1 = a-F1. After the second equation, you have R1 = a-F1 and R2 = a-F1. Each variable can be represented by two numbers: some number times the first variable in their partition, plus a constant. Then at the end, you go through each partition, and look for variables that have the same two numbers representing them.

Acccumulation
  • 3,491
  • 1
  • 8
  • 12