Ask Your Question
0

solve() is not giving the right solutions

asked 2018-11-15 15:17:54 +0100

bentheteacher gravatar image

updated 2018-11-15 15:18:40 +0100

Hey there,

i need your help on this one. The following sage code is giving me a headache:

  • f(x) = x^3 + x^2 - 0.1
  • solve(f==0, x)
  • -->
  • [x == -1/2(1/180Isqrt(13)sqrt(3) + 7/540)^(1/3)(Isqrt(3) + 1) - 1/18(-Isqrt(3) + 1)/(1/180Isqrt(13)sqrt(3) + 7/540)^(1/3) - 1/3, x == -1/2(1/180Isqrt(13)sqrt(3) + 7/540)^(1/3)(-Isqrt(3) + 1) - 1/18(Isqrt(3) + 1)/(1/180Isqrt(13)sqrt(3) + 7/540)^(1/3) - 1/3, x == (1/180Isqrt(13)sqrt(3) + 7/540)^(1/3) + 1/9/(1/180Isqrt(13)sqrt(3) + 7/540)^(1/3) - 1/3]

So i'm getting these 3 solutions, but they are not in R (real numbers), which they should be. Im figuring there is some problem with really long terms or something? Is there an easy solution for this? Is the solve()-method here working as intended?

Regards, Ben

edit retag flag offensive close merge delete

Comments

See casus irreducibilis...

You can get "ostensibly real" solutions by expressing the quantities in trigonometric form. For example :

sage: map(lambda s:s.rhs().imag_part().trig_expand(), (x^3+x^2-1/10).solve(x))
[0, 0, 0]
Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2018-11-15 18:39:11 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2018-11-15 15:32:41 +0100

tmonteil gravatar image

Note that even if I appears in the solutions, the solutons are actually real, we can simplify the right-hand side of each solution, and see that I cancel eachother:

sage: s = solve(f==0, x)
sage: [i.rhs().full_simplify() for i in s]
[-1/9*sqrt(3)*(sqrt(3)*cos(1/3*arctan(3/7*sqrt(13)*sqrt(3))) + sqrt(3) - 3*sin(1/3*arctan(3/7*sqrt(13)*sqrt(3)))),
 -1/9*sqrt(3)*(sqrt(3)*cos(1/3*arctan(3/7*sqrt(13)*sqrt(3))) + sqrt(3) + 3*sin(1/3*arctan(3/7*sqrt(13)*sqrt(3)))),
 2/3*cos(1/3*arctan(3/7*sqrt(13)*sqrt(3))) - 1/3]

Note that 0.1 is interpreted as 1/10 in the symbolic ring, so that the solutions are symbolic and not numerical.

edit flag offensive delete link more

Comments

I figured that it would cancel each other, but i wasnt aware of the simplify-method. Thank you, im going to try this! :)

e: im still wondering if it should be this way. If i test this with "in RR" i get false which is not true as u said yourself... thats kinda odd

bentheteacher gravatar imagebentheteacher ( 2018-11-15 18:15:10 +0100 )edit

sage: RR Real Field with 53 bits of precision

Working in RR entails rounding errors, i. e. imperfect representation of quantities with no finite binary representation, hence inequalities where equalities are expected...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2018-11-15 18:48:04 +0100 )edit
0

answered 2018-11-18 20:15:54 +0100

slelievre gravatar image

Instead of defining f as a sympolic expression and using solve, one can define f as a polynomial over the rationals, and get its roots over the algebraic numbers.

Define ring of polynomials in x over the rationals, then f:

sage: R.<x> = QQ[]
sage: f = x^3 + x^2 - 1/10

Roots of f in QQbar (they are real: no imaginary part is shown):

sage: rr = f.roots(QQbar, multiplicities=False)
sage: print(rr)
[-0.8669513175959773?, -0.4126055722546906?, 0.2795568898506678?]

Further check that all roots are real:

sage: [r.imag() == 0 for r in rr]
[True, True, True]

Get radical expressions (involving I even though all roots are real).

sage: [r.radical_expression() for r in rr]
[-1/2*(1/180*I*sqrt(13)*sqrt(3) + 7/540)^(1/3)*(-I*sqrt(3) + 1)
 - 1/18*(I*sqrt(3) + 1)/(1/180*I*sqrt(13)*sqrt(3) + 7/540)^(1/3) - 1/3,
 -1/2*(1/180*I*sqrt(13)*sqrt(3) + 7/540)^(1/3)*(I*sqrt(3) + 1)
 - 1/18*(-I*sqrt(3) + 1)/(1/180*I*sqrt(13)*sqrt(3) + 7/540)^(1/3) - 1/3,
 (1/180*I*sqrt(13)*sqrt(3) + 7/540)^(1/3)
 + 1/9/(1/180*I*sqrt(13)*sqrt(3) + 7/540)^(1/3) - 1/3]

See link provided by @Emmanuel_Charpentier for the mathematics of that.

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: 2018-11-15 15:17:54 +0100

Seen: 457 times

Last updated: Nov 18 '18