[SciPy-User] fsolve with restriction on variable

Sebastian Walter sebastian.walter at gmail.com
Tue Aug 4 04:49:02 EDT 2009


what you can try to do is using a penalty method:

x_* = argmin_x f(x)
subject to  g(x) <= 0

then you can try to do:

x_* = argmin_x f(x) + \rho (max(g(x), 0))^p
where e.g. p =2, and make \rho large

problem: badly conditioned for \rho very large.

But that's still much better than adding a constant when g(x) > 0!



2009/8/4 Ernest Adrogué <eadrogue at gmx.net>:
>  3/08/09 @ 12:49 (-0400), thus spake Ashley DaSilva:
>> Hello,
>>
>> I am using fsolve to solve a function, f(v), v=[x,y,z] is a list of three
>> variables. However, I have a factor in f which contains (1-x**2)**(7./2).
>> So, when I do the following,
>> fsolve(f,x0)
>> the code eventually tries x= -1.57, which clearly produces an error in my
>> function due to the power 7./2.
>>
>> I know that the solution for x should be between 0 and 1, is there a way to
>> put this restriction on x while using fsolve?
>
> I ran into the same problem.
> One thing you can try is add a couple of lines to your function
> so that it returns a constant value (which is not a solution to your
> problem) when (1-x**2) < 0, instead of the actual calculation.
> In my case it did the trick.
>
> Ernest
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>



More information about the SciPy-User mailing list