Using excel solver, it is easy to find a solution (optimum value for x and y )for this equation:
(x*14.80461) + (y * -4.9233) + (10*0.4803) ≈ 0
However, I can’t figure out how to do this in Python. The existing scipy optimize library function like fsolve() or leastsq() seems to work with only one variable…. (I might just not know how to use them)…
Any suggestions?
Thanks!
Since the solution is not unique, different initial values for an unknown lead to different (valid) solutions.
EDIT: Why this works. Well, it’s a dirty hack. It’s just that
fsolveand its relatives deal with systems of equations. What I did here, I defined a system of three equations (f(x)returns a three-element list) for three variables (xhas three elements). Nowfsolveuses a Newton-type algorithm to converge to a solution.Clearly, the system is underdefined: you can specify arbitrary values of two variables, say,
x[1]andx[2]and findx[0]to satisfy the only non-trivial equation you have. You can see this explicitly by specifying a couple of initial guesses forx0and see different outputs, all of which satisfyf(x)=0up to a certain tolerance.