How to solve this equation with SciPy
<p>In MathCad it looks like this:</p>

<p><a href="http://i.stack.imgur.com/8rWer.png" rel="nofollow"><img src="http://i.stack.imgur.com/8rWer.png" alt="enter image description here"></a></p>

<p>How to solve it using python (scipy or sympy)?</p>

<p>Maybe something like this?</p>

<pre><code>def fun(n):
    x, y, z = n
    return -0.7353 + 3.306 * np.absolute(0.706 - x) + 1.247 * np.absolute(0.7210 - y) - (0.89072 - 1.4829*x + 0.23239*y - z)
scipy.optimize.fsolve(fun, [1,1,1])
</code></pre>

<h3>Code</h3>

<p>The important thing (for this scipy.minimize based approach) is the quadratic penalization of the error (which is the difference of both sides). Of course there are other approaches, but be careful to bound the objective.</p>

<pre><code>from scipy.optimize import minimize

fun = lambda x: ((-0.7353 + 3.306 * (abs(0.706 - x[0])) + 1.247 * (abs(0.721 - x[1]))) - \
                (0.89072 - 1.4829 * x[0] + 0.23239 * x[1] - x[2]))**2
x0 = [1, 1, 1]
res = minimize(fun, x0, tol=1e-6)
print(res)
</code></pre>

<h3>Result</h3>

<pre><code>fun: 1.180300596982825e-18
hess_inv: array([[ 0.01850105, -0.02426119, -0.04300235],
 [-0.02426119,  0.23287182,  0.24090596],
 [-0.04300235,  0.24090596,  0.61570727]])
jac: array([  5.34881862e-08,   3.58270711e-08,   1.27283284e-08])
message: 'Optimization terminated successfully.'
nfev: 50
nit: 6
njev: 10
status: 0
success: True
x: array([ 0.69247018, -0.38146035, -0.90898925])
</code></pre>

<p>As mentioned in the comments, there is <strong>no unique solution</strong>. Your start-point and chosen algorithm decides what kind of solution you get.</p>

<p>The only relevant part is the <strong>objective, which should approach zero!</strong></p>

python numpy scipy sympy