I am trying to check if a list of resistors can be used to achieve a set of equivalent resistances. (Reciprocal of the sum of the reciprocals of the individual resistors is the equivalent resistance) Achieving the exact value of equivalent resistance is very tough, so I would like to allow a tolerance of 5% max. privArrayTest generates a list of all combinations of the resistors and calculates the equivalence. I attempted to implement the tolerance with tolerance[x_], and run that through ContainsAll, but it appears to just be checking the edge values rather than values within the range.
ParallelResist[arrayInTest_, arrayInCompare_] :=
Module[{privArrayTest, invert, sum, privArrayC, tolerance},
(*internal functions*)
invert[x_] := x^-1;
sum[x_] := Total[x];
tolerance[x_] := {x - x*.05, x + x*.05};
(*main body*)
privArrayTest = Map[invert, N[Map[sum, Subsets[Map[invert, arrayInTest], {1, \[Infinity]}]]]];
(*1,\[Infinity] prevents the first blank subset from being \generated*)
privArrayC = Map[tolerance, arrayInCompare];
Print[privArrayC]; (*Debugging Code*)
Print["Debug code,privArrayTest", privArrayTest];(*Debugging code*)
(*compare code, returns true false*)
ContainsAll[privArrayTest, privArrayC]
]
Example input:
resistors = {1500, 1000, 2500, 20000};
equivalence = {472.441, 483.871, 895.522};
Example output:
{{448.819,496.063},{459.677,508.065},{850.746,940.298}}
Debug code,privArrayTest{1500.,1000.,2500.,20000.,600.,937.5,1395.35,714.286,952.381,2222.22,483.871,582.524,895.522,689.655,472.441}
True