William Stein wrote:
> On 10/28/07, David Joyner <[EMAIL PROTECTED]> wrote:
>> On 10/26/07, Jason Grout <[EMAIL PROTECTED]> wrote:
>>> I'm trying to numerically solve a system of equations.  Currently I have:
>>>
>>> sage: var('x y p q')
>>> sage: eq1 = p+q==9
>>> sage: eq2 = q*y+p*x==-6
>>> sage: eq3 = q*y^2+p*x^2==24
>>> sage: solve([eq1,eq2,eq3,p==1],p,q,x,y)
>>> [[p == 3, q == 6, x == (-2*sqrt(10) - 2)/3, y == (sqrt(2)*sqrt(5) -
>>> 2)/3], [p == 3, q == 6, x == (2*sqrt(10) - 2)/3, y == (-sqrt(2)*sqrt(5)
>>> - 2)/3]]
>>>
>>> I'd like the answer to be a numeric approximation, though (i.e.,
>>> x==-2.77485177345).  I can't find any other solving routines other than
>>> the symbolic one, though.  Is there a way to numerically approximate the
>>> solution, other than going through each solution and calling n() on the
>>> left side of each symbolic expression?
>>
>> Examples using numpy and octave are give in the constructions cookbook:
>>
>> http://www.sagemath.org/doc/html/const/node35.html
> 
> Note that his systems are nonlinear, but your examples
> in the constructions book are linear.  So it's sort of
> a different thing.

William is correct here.

> 
> Some options for solving systems of nonlinear equations  *numerically* 
> include:
> 
>   * [100% sage] Use scipy, which wraps minpack:
> Type
>    sage: import scipy.optimize
>    sage: scipy.optimize.fsolve ?
> to hopefully get going.   Also just try scipy.optimize.[tab]

I saw this late Saturday night and tried to get it working, but haven't 
been successful yet.  I think it's a matter of figuring out what fsolve 
is expecting to be passed and how to interpret the results (e.g., it 
appears that fsolve expects the function to take a vector, or list of 
parameters, and not just a bunch of parameters).



> 
>   * [Not sage] Use phcpack, which is open source (GPL'd) but not
> included in Sage. It is able to do amazing things with solving
> algebraic systems numerically, using a method called "Polynomial
> Homotopy Continuation".  There is a Sage interface to phcpack, that
> Marshall Hampton worked on (he frequently posts on sage-devel).

Thanks for this tip as well.

For now, I just ended up making a patch for the functionality that I 
wanted (isn't that what we encourage here? :).  Carl merged it into 
2.8.10 last night.  It adds a solution_dict optional parameter to solve 
that returns a dictionary of the solutions.  This makes it easy to refer 
to the values in a solution.  Using the solution_dict option, my 
original problem may be solved with:

sage: var('x y p q')
sage: eq1 = p+q==9
sage: eq2 = q*y+p*x==-6
sage: eq3 = q*y^2+p*x^2==24
sage: solutions=solve([eq1,eq2,eq3,p==1],p,q,x,y, solution_dict=True)
sage: for solution in solutions: print solution[p].n(), solution[q].n(), 
solution[x].n(), solution[y].n()


However, it would still probably be more efficient to use fsolve or the 
other method above since I don't need the symbolic solution.  I'll look 
at getting fsolve to work and post an example of working code.

Thanks,

Jason


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to