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

Ryan Nelson rnelsonchem at gmail.com
Sat Mar 21 17:28:29 EDT 2015


For scipy.optimize.minimize, the function needs to take all of the values
as a tuple, and it should return a single y value. For a silly example:
####
def func(x):
    x1 = x[0]
    x2 = x[1]
    y = x1**2 + x2**2
    return y

fit = scipy.optimize.minimize(func, [10, 3])
####
Right now, your function spits out two y values, which that function can't
handle. The minimizer will do the work of "compute_new_x1", etc.

I hope this helps you with your problem. If not, it might be useful to have
a simple, but complete, example.

Ryan


On Sat, Mar 21, 2015 at 3:00 PM, Camille Chambon <camillechambon at yahoo.fr>
wrote:

> Hello,
>
> I have a function:
>
> def my_function(x1, x2):
>      y1 = compute_y1(x1)
>      y2 = compute_y2(x2)
>      x1_new = compute_new_x1(x1, y1, y2)
>      x2_new = compute_new_x2(x2, y1, y2)
>      return x1_new, x2_new, y1, y2
>
> I would like to find the convergent values of y1 and y2, that is when
> (x1_new - x1) / x1 < epsilon and (x2_new - x2) / x2 < epsilon.
>
> By now, I initialize x1 and x2 and I call main_function numerous times:
>
> epsilon = 0.01
> x1, x2 = 0.1, 0.1
> x1_new, x2_new = 100.0, 100.0
> while abs((x1_new - x1)/x1) >= epsilon or abs((x2_new - x2)/x2) >= epsilon:
>      x1, x2 = x1_new, x2_new
>      x1_new, x2_new, y1, y2 = my_function(x1, x2)
> print 'y1 = ', y1
> print 'y2 = ', y2
>
> It works. But I wonder if it's the most efficient method.
>
> I read about scipy.optimize.minimize, but I can not see how it could be
> applied to my problem.
>
> Thanks in advance for your help.
>
> Cheers,
>
> Camille
> _______________________________________________
> 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/20150321/5c0bd593/attachment.html>


More information about the SciPy-User mailing list