Ask Your Question
0

Sage solver : approximate solution

asked 2020-11-26 18:50:37 +0200

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
0

answered 2020-11-26 19:40:24 +0200

Emmanuel Charpentier gravatar image

updated 2020-11-26 19:42:33 +0200

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[1].solve(x8)[0].rhs()-Sys[0].solve(x8)[0].rhs()
-9631419/1809844328933473637045
sage: (Sys[1].solve(x8)[0].rhs()-Sys[0].solve(x8)[0].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[0].solve(x8)[0].rhs()
15965419/17280845
sage: Sys[1].solve(x8)[0].rhs()
96759049255592/104731240221961

You can obtain floating-point solutions :

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

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

Stats

Asked: 2020-11-26 18:50:37 +0200

Seen: 63 times

Last updated: Nov 26 '20