Home > Mobile >  Percentage weighting given two variables to equal a target
Percentage weighting given two variables to equal a target

Time:10-05

I have a target of target = 11.82 with two variables

x = 9 y = 15

How do I find the percentage weighting that would blend x & y to equal my target? i.e. 55% of x and 45% of y - what function is most efficient way to calc a weighting to obtain my target?

CodePudding user response:

Looking at it again, what I think you want is really two equations:

 9x   15y = 11.82
 x   y = 1

Solving that system of equations is pretty fast on pen and paper (just do linear combination). Or you could use sympy to solve the system of linear equations:

>>> from sympy import *
>>> from sympy.solvers.solveset import linsolve
>>> x, y = symbols('x, y')
>>> linsolve([x   y - 1, 9 * x   15 * y - 11.82], (x, y))  # make 0 on right by subtraction
FiniteSet((0.53, 0.47))

We can confirm this by substitution:

>>> 9 * 0.53   15 * 0.47
11.82
  • Related