# Numerical approximations

g(x)=x^2-sqrt(2)
solve(g(x)==0,x)

[x == -2^(1/4), x == 2^(1/4)]


What's the best/quickest way to get numerical approximations of these values of x? Thanks.

edit retag close merge delete

Sort by » oldest newest most voted

With my background neither is particularly straight-forward but I am happy to learn about both methods. Thanks.

more

In your case, since g can be seen as a polynomial, you can also look at its roots in the real double field (floating-point approximations with 53 bits of precision):

sage: g.polynomial(RDF).roots()
[(-1.189207115002721, 1), (1.189207115002721, 1)]

more

I see two ordered pairs, I think, but if that's so I don't understand why the y-values are 1 and not 0.

OK. "The first of the pair is the root, the second of the pair is its multiplicity."

Try taking the right hand side of each solution.

sage: A =    solve(g(x)==0,x)
sage: [a.rhs().n() for a in A]
[-1.18920711500272, 1.18920711500272]


where n() is short for numerical_approx(). There are other ways of approaching this as well, such as via the solution_dict=True keyword to solve().

more