Ask Your Question

# finding real zeros of polynomials [was "numerical value"]

asked 2011-04-03 09:09:13 -0500 This post is a wiki. Anyone with karma >750 is welcome to improve it.

## Code:

for n in range (1,11):
print "n =", n
y = solve(gen_legendre_P(n, 0, x) == 0, x)
print "Zeros: {",
for i, eq in enumerate(y):
print eq.rhs().n(digits=2),
print ",",
print "}"


for n = 9 we get: Zeros: { -0.96 - 7.5e-6 * I , 0.96 + 7.5e-6 * I , -0.83 - 0.000039 * I , 0.83 + 0.000039 * I , -0.62 + 0.000052 * I , 0.62 - 0.000052 * I , -0.33 + 0.000024 * I , 0.33 - 0.000024 * I , 0.00 , }

and for n = 10 we get:

Zeros: {
Traceback (click to the left of this block for traceback)
...
TypeError: cannot evaluate symbolic expression numerically


1) How to get rid of for example. (-0.96 - 7.5e-6 * I) and get real numbers like (-0.96816) ?

2) Why n = 10 don't work?

edit retag close merge delete

## 2 answers

Sort by » oldest newest most voted

answered 2011-04-03 14:05:58 -0500 This post is a wiki. Anyone with karma >750 is welcome to improve it.

"2) Why n = 10 don't work?"

Look at the equation it's trying to solve:

sage: solve(gen_legendre_P(10, 0, x) == 0, x)
[0 == 46189*x^10 - 109395*x^8 + 90090*x^6 - 30030*x^4 + 3465*x^2 - 63]


after substituting x^2->y, this is a 5th-order polynomial in y, and in general you can't solve an arbitrary polynomial higher than fourth order by radicals. This result is known as the Abel-Ruffini theorem.

The good news is that if you only care about numerical values, you can work in a polynomial ring over a real or complex field and get numerical results:

R.<x> = RealField(100)[]
for n in [1..10]:
p = gen_legendre_P(n, 0, x)
print n, p.real_roots()

1 [0.00000000000000000000000000000]
2 [-0.57735026918962576450914878050, 0.57735026918962576450914878050]
3 [-0.77459666924148337703585307996, 0.00000000000000000000000000000, 0.77459666924148337703585307996]
4 [-0.86113631159405257522394648889, -0.33998104358485626480266575910, 0.33998104358485626480266575910, 0.86113631159405257522394648889]
5 [-0.90617984593866399279762687830, -0.53846931010568309103631442070, 0.00000000000000000000000000000, 0.53846931010568309103631442070, 0.90617984593866399279762687830]
6 [-0.93246951420315202781230155449, -0.66120938646626451366139959502, -0.23861918608319690863050172168, 0.23861918608319690863050172168, 0.66120938646626451366139959502, 0.93246951420315202781230155449]
7 [-0.94910791234275852452618968405, -0.74153118559939443986386477328, -0.40584515137739716690660641208, 0.00000000000000000000000000000, 0.40584515137739716690660641208, 0.74153118559939443986386477328, 0.94910791234275852452618968405]
8 [-0.96028985649753623168356086857, -0.79666647741362673959155393647, -0.52553240991632898581773904919, -0.18343464249564980493947614236, 0.18343464249564980493947614236, 0.52553240991632898581773904919, 0.79666647741362673959155393647, 0.96028985649753623168356086857]
9 [-0.96816023950762608983557620291, -0.83603110732663579429942978806, -0.61337143270059039730870203934, -0.32425342340380892903853801464, 0.00000000000000000000000000000, 0.32425342340380892903853801464, 0.61337143270059039730870203934, 0.83603110732663579429942978806, 0.96816023950762608983557620291]
10 [-0.97390652851717172007796401209, -0.86506336668898451073209668842, -0.67940956829902440623432736512, -0.43339539412924719079926594316, -0.14887433898163121088482600113, 0.14887433898163121088482600113, 0.43339539412924719079926594316, 0.67940956829902440623432736512, 0.86506336668898451073209668842, 0.97390652851717172007796401209]


The line R.<x> = RealField(100)[] generates a one-variable polynomial ring called R over (an approximation to) the real field, in this case with 100 bits of precision, and defines a variable "x" which lives there:

sage: R.<x> = RealField(100)[]
sage: R
Univariate Polynomial Ring in x over Real Field with 100 bits of precision
sage: x
x
sage: parent(x)
Univariate Polynomial Ring in x over Real Field with 100 bits of precision

more

answered 2011-04-03 09:44:15 -0500 This post is a wiki. Anyone with karma >750 is welcome to improve it.

the first one is easy replace

print eq.rhs().n(digits=2)


by

print eq.rhs().n(digits=2).real()


or

print eq.rhs().n(digits=2).abs()


The second one I don't know for some reason "solve" is not able to solve the equation.

more

## Your Answer

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

Add Answer

## Stats

Asked: 2011-04-03 09:09:13 -0500

Seen: 1,166 times

Last updated: Apr 23 '11
{"ft_lang_label":"__label__en","ft_lang_prob":0.52536476,"math_prob":0.9393854,"size":2942,"snap":"2019-35-2019-39","text_gpt3_token_len":1102,"char_repetition_ratio":0.1102791,"word_repetition_ratio":0.073469386,"special_character_ratio":0.75628823,"punctuation_ratio":0.28794643,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9710076,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,null,null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-08-18T03:19:39Z\",\"WARC-Record-ID\":\"<urn:uuid:4ff77333-6cf4-4aba-abc9-28bc9844a894>\",\"Content-Length\":\"61700\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:44296dc3-0a3f-45d9-b0e8-8a4fa11e110c>\",\"WARC-Concurrent-To\":\"<urn:uuid:1bc148d4-82c5-4cc5-93c5-7d2c1ea67464>\",\"WARC-IP-Address\":\"140.254.118.68\",\"WARC-Target-URI\":\"https://ask.sagemath.org/question/8052/finding-real-zeros-of-polynomials-was-numerical-value/\",\"WARC-Payload-Digest\":\"sha1:LBEMLM7MPIPGPSX23AA2RRBENCGTOBIW\",\"WARC-Block-Digest\":\"sha1:N3XASWKFMCIIIN5IV22MBQAQ3ZF2WD6B\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-35/CC-MAIN-2019-35_segments_1566027313589.19_warc_CC-MAIN-20190818022816-20190818044816-00191.warc.gz\"}"}