Search code examples
pythonnumpyfault-tolerance

Tolerance stack combination with 3 resistor values


I am trying to do perform a simple tolerance stack circuit analysis using python instead of excel. Basically, say I have the resistor values below where it is separated by -> Minimum | Nominal | Maximum, hence the value below:

R1 -> 5 | 10 | 15 R2 -> 5 | 10 | 15

Total_R = R1 + R2

In theory, this would generate 9 combinations of 'Total_R' going from (minimum of R1 + minimum of R2) until (maximum of R1 + maximum of R2)

How can I perform this in python effectively to accommodate maybe up to 10 Resistor values?


Solution

  • What you want is called Cartesian product. Python has a function for them: itertools.product:

    from itertools import product
    
    R1 = (5, 10, 15)
    R2 = (13, 1313, 131313)
    
    list(product(R1, R2))
    

    will return you:

    [(5, 13),
     (5, 1313),
     (5, 131313),
     (10, 13),
     (10, 1313),
     (10, 131313),
     (15, 13),
     (15, 1313),
     (15, 131313)]