Ask Your Question

Sage solver : approximate solution

asked 2020-11-26 11:50:37 -0600

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 flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2020-11-26 12:40:24 -0600

Emmanuel Charpentier gravatar image

updated 2020-11-26 12:42:33 -0600

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")
sage: Sys=[1.00000000000000*x8 == 0.923879532511287,0.414213562373096*x8 == 0.382683432365089]
sage: Sys[1].solve(x8)[0].rhs()-Sys[0].solve(x8)[0].rhs()
sage: (Sys[1].solve(x8)[0].rhs()-Sys[0].solve(x8)[0].rhs()).n()

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[0].solve(x8)[0].rhs()
sage: Sys[1].solve(x8)[0].rhs()

You can obtain floating-point solutions :

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

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

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-11-26 11:50:37 -0600

Seen: 31 times

Last updated: Nov 26 '20