I have the following data:
- Number of views (
n
) - Mean position in search (
m
) - Possible values for position:
1
to8
I need to calculate the possible variations of values.
Ex: n = 4442
, m = 1.1
. So, the variations would be:
(1*x + 2*y + ... + 8*z) / 4442 = 1.1
Or, given that the mean almost equals 1, it makes sense to find variations for 1, 2 and 3 positions in search. I want to get tuples (x1, y1, z1)
etc.
I have rewritten the equation as:
(1*x + 2*y + 3*z) / 4442 - 1.1 = 0
I have tried to use SymPy's Diophantine equation solver for 2 unknowns. But if I understand correctly, it only works with integer coefficients, while I have a floating coefficient (mean values), so it didn't work. How should I approach this?
from sympy import *
x, y = symbols('x, y', integer=True)
eq = (1*x + 2*y)/4442 - 1.1
conds = [(0 < x), (x <= 4442), (0 <= y), (y < 4442)]
#Solve the diophantine equation for solutions in parameter t_0
t, t_0 = symbols('t, t_0', integers = True)
gensol = diophantine(eq, t, [x, y])
((xs, ys),) = gensol
#"Solve" the inequalities for constraints on t_0
conds_t = [cond.subs(x, xs).subs(y, ys) for cond in conds]
conds_t_sol = solve(conds_t, t_0)
#Find the finite set of values for t_0 and sub in to general solution
set_t0 = (conds_t_sol.as_set() & Integers)
sol_set = [(xs.subs(t_0, ti), ys.subs(t_0, ti)) for ti in set_t0]
print(sol_set)