# Sage solver : approximate solution

I have the simple following equation :

res = solve([1.00000000000000*x8 == 0.923879532511287,0.414213562373096*x8 == 0.382683432365089],x8,solution_dict=True)


However, the solver will return an empty solution because the value do not quite exactly match (there is a 1e-15 difference that is due to numerical errors of the 53 bits mantissa precision). Is there a way to ask the solver to get an approximate solution instead?

edit retag close merge delete

Sort by » oldest newest most voted

Your first equation is an approximate solution (the coefficient of x8 is indistinguishable from 1) .

It turns out that your two equations are not equivalent :

sage: var("x8")
x8
sage: Sys=[1.00000000000000*x8 == 0.923879532511287,0.414213562373096*x8 == 0.382683432365089]
sage: Sys.solve(x8).rhs()-Sys.solve(x8).rhs()
-9631419/1809844328933473637045
sage: (Sys.solve(x8).rhs()-Sys.solve(x8).rhs()).n()
-5.32168366418327e-15


And Sage is right in telling you that your system has no solution.

Workarounds :

• Obtain exact values for your systems' coefficients ;

• solve for one equation, use the second to estimate the error, and decide if you want to accept this as an approximation. ;

• treat your system as a system of redundant equations and search for the least-squares solution (left as an exercise for the reader...).

Note, by default, Sage (9.3.beta2) converts your equations' coefficients to rational approximations :

sage: Sys.solve(x8).rhs()
15965419/17280845
sage: Sys.solve(x8).rhs()
96759049255592/104731240221961


You can obtain floating-point solutions :

sage: (Sys.lhs()-Sys.rhs()).roots(ring=RR, multiplicities=False)
[0.923879532511287]
sage: (Sys.lhs()-Sys.rhs()).roots(ring=RR, multiplicities=False)
[0.923879532511283]


And it turns out that, even in the inexact ring RR, your equations are not equivalent.

more