Given the equation: 10 = 2x + 3y + 2z
, I want to find all the combination of x, y and z between 2 thresholds (e.g. -100 and 100) that make the equation hold true.
So far, I have tried the following with no success (please see the comments):
set.seed(333)
result = 10
# sample random values from uniform distribution
x = runif(100, -100, 100)
y = runif(100, -100, 100)
z = runif(100, -100, 100)
# store the vectors in a single dataframe
df = data.frame(x, y, z)
# find all the combinations of x, y and z
expanded = expand.grid(df)
# calculation with all the combinations
expanded$result = ((expanded$x * 2) + (expanded$y * 3) + (expanded$z * 2)) == result
# show the data where result is 10
expanded[expanded$result, ]
[1] x y z result
<0 rows> (or 0-length row.names)
How would I achieve this?