Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How do I get solve () to use floats?

I want to solve a system of two (nonlinear) equations in floats. What the Sage documentation suggests I do is this:

var('x y')

eq1 = (x-x0)^2 +(y-y0)^2 == d0^2

eq2 = (x-x1)^2 + (y-y1)^2 == d1^2

solns = solve([eq1, eq2], x, y)

[[s[x].n(30), s[y].n(30)] for s in solns]

x0, x1, y0, y1, d0, and d1 are constants, by the way.

But this just solves it exactly and then approximates it. I don't want that! I need to solve this equation hundreds to thousands of times quickly, and the exact solving takes a really long time, creating a short delay to even solve one equation. I want to just solve in floats from the beginning.

I could solve the equations symbolically myself and plug them into the program as expressions in x and y. But the expressions are really long and not only is that a huge error-prone pain to type up (the expressions would take up several lines for each variable, not to mention that there are two solutions), but I have to solve several different equations that will be like this. I want to avoid doing this if at all possible.

I've tried using find_root, but I don't know how it works on systems, I've tried just putting floats into the equation, I've tried setting domain=float, RR, and RDF in the solve function, and a bunch of other random things that I don't even remember. How do I do this?