Mike wrote:
>> Hi,
>> I am using solve to solve higher order simultaneous equations in two
>> variables. solve is able to do that, however I have not been able to
>> convert the results to int or float. Specifically I did :
>>
>>>>> from sympy import Symbol
>>>>> A=solve((x**2 - 1 + y**2 - 2*x*y-6,3*x**2 + 4*y-2),x,y)
>>
>> What A looks like can be seen at http://pastebin.com/abWtaxWG (didn't
>> want to paste a large chunk of text that contains the fractions). On
>> doing the following, I get an error:
>>>>> A[0] + 1
>> Traceback (most recent call last):
>> File "<stdin>", line 1, in <module>
>> TypeError: can only concatenate tuple (not "int") to tuple
>>
>> From what I understand (and i am new to sympy), the results in A are
>> nicely formatted and are of the type tuple hence this does not work.
>> But what can I do to convert them to float.
When you're stuck with a problem like this it's a good idea to try solve a
toy-class set of equations so you can see more clearly what you are dealing
with:
>>> solve((x+y-5,x-y-1),x,y) # a system with a single solution
{x: 3, y: 2}
>>> solve((x+y-5,x-y**2+1),x,y) # s system with two solutions
[(3, 2), (8, -3)]
So you are dealing with the second case. When you type A[0] + 1 you are trying
to add 1 to the (x, y) tuple...which doesn't make sense. You can extract your
values of x and y and then do something with them, though. Continuing from the
previous output...
>>> A = _; xi, yi = A[0]
>>> xi+yi
5
>> Also, in general can you comment on how good solve is. I am
>> evaluating whether to use solve against fsolve. Since fsolve solves
>> multinomial
>> roots by optimization it can get into local minimas IMO. However,
>> will using solve from sympy result in a smaller set of problems which can
>> be solved.
>>
Yes, for now you may run into lots of error-raising experiences. I am waiting
for polys12 to get in place and for someone to review the changes I've made to
the solver for single equations. Once these are in place the solver situation
is going to improve significantly.
/c
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sympy?hl=en.