questions about solving equations in scipy

fdu.xiaojf at gmail.com fdu.xiaojf at gmail.com
Wed Jun 13 03:28:17 EDT 2007


Hi Robert,

Thanks a lot for your kindness.

Robert Kern wrote:
> fdu.xiaojf at gmail.com wrote:
>> Hi all,
>>
>> I have two questions about scipy.
>
> You're likely to get a better response from the scipy mailing list. Here, 
you'll
> primarily get me, and I have to rush out right now.
>
>   http://www.scipy.org/Mailing_Lists
  In fact, I have tried to subscribe to the list, but got no response. I
  will try again.
>
>> 1) When I was trying to solve a single variable equations using scipy, I
>> found two methods: scipy.optimize.fsolve, which is designated to find the
>> roots of a polynomial,
>
> No, it finds the roots of a non-linear system of N functions in N 
variables. The
> documentation makes no mention of polynomials.
>
>> and scipy.optimize.newton, which is used for Scalar
>> function root finding according to the help().
>
> There's also brentq, brenth, ridder, and bisect for this problem.

>
>> I have tried both, and it seemed that both worked well, and fsolve ran
>> faster.
>>
>> My questions is, which is the right choose ?
>
> Whichever one works faster and more robustly for your problem. fsolve is
> implemented in FORTRAN, which sometimes helps. I do recommend looking at the
> brentq and brenth if you can provide bounds rather than just an initial guess.

"brentq" or "brenth" are used to find a zero of the function f between the
argument a and b. It demanded that f(a) and f(b) can not have the same signs.
I think it is very convenient to provide valid a and b before I've got the
solution of the function.
>
>> 2) I have to solve a linear equation, with the constraint that all
>> variables should be positive. Currently I can solve this problem by
>> manually adjusting the solution in each iteration after get the solution
>> bu using scipy.linalg.solve().
>>
>> Is there a smart way ?
>
> I don't think that's a well-defined problem. Either the (unique) solution is
  I found a web page about optimization solver in openoffice(

http://wiki.services.openoffice.org/wiki/Optimization_Solver#Non-Linear_Programming).
  Openoffice has an option of "Allow only positive values", so I think that's a
  well-defined problem. Sorry for my ignorance if I was wrong.

> within the constraint or it's not. Are you sure you don't want to find the
> minimum-error solution that obeys the constrain, instead?
  Yes, I do want to find the minimum-error solution that obeys the constrain.
  Please tell me more !


  Regards,

  Xiaojf




More information about the Python-list mailing list