[SciPy-User] Find the convergent solutions of a multivariate equation efficiently

Camille Chambon camillechambon at yahoo.fr
Wed Mar 25 06:23:34 EDT 2015


Yes. Sorry. I wrote this simplified system quickly without thinking of 
its meaningfulness. The original system is convergent, but too much 
complex to be shared and can not be simplified.

To summary, my system looks like:

  * y1 = g1(x1, x2)
  * y2 = g2(y1)
  * next_x1 = f1(y1, y2)
  * next_x2 = f2(y2, x2)
  * (next_x1 - x1) / x1 < epsilon
  * (next_x2 - x2) / x2 < epsilon

What I want to compute is y1 and y2.

I can do it like that:

x1, x2 = x1_0, x2_0
while True:
     y1 = g1(x1, x2)
     y2 = g2(y1)
     next_x1 = f1(y1, y2)
     next_x2 = f2(y2, x2)
     if abs((x1_new - x1)/x1) < epsilon and abs((x2_new - x2)/x2) < epsilon:
         break
print 'y1', y1, 'y2', y2

I also manage to use scipy.optimize.root:

def fun(x, y1_y2):
     x1 = x[0]
     x2 = x[1]
     y1 = g1(x1, x2)
     y2 = g2(y1)
     next_x1 = f1(y1, y2)
     next_x2 = f2(y2, x2)
     y1_y2[:] = y1, y2
     return [(next_x1 - x1) / x1, (next_x2 - x2) / x2]

from scipy import optimize
import numpy as np
y1_y2 = np.zeros(2)
sol = optimize.root(fun, [x1_0, x2_0], (y1_y2,))
print 'y1', y1_y2[0], 'y2', y1_y2[1]

Both work fine. But using timeit(...), the solution with 
scipy.optimize.root is twenty times slower than the one with the while 
loop. Is it normal?
Maybe scipy.optimize.root is much slower because I don't give it a 
Jacobian ? But I can't define the Jacobian matrix because my system is 
too complex.
Maybe scipy.optimize.root is just not appropriate to solve my system?

Thanks again for your help.

Cheers,

Camille

Le 24/03/2015 19:21, Pauli Virtanen a écrit :
> 24.03.2015, 15:47, Camille Chambon kirjoitti:
> [clip]
>> Do I use scipy.optimize.fixed_point and scipy.optimize.root in a bad way?
> Your iteration is:
>
> 	x1[n+1] = x1[n] + 10
> 	x2[n+1] = x2[n] + 10
>
> It has no fixed point, both x1 and x2 diverge to infinity.
>
> The results returned by your while_iterations() do not have meaning,
> they depend on the tolerance 0.01 you used. If you use smaller
> tolerance, the results diverge.
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20150325/f75b3b21/attachment.html>


More information about the SciPy-User mailing list