# Singular

 Page 1 of 1 [ 2 posts ]
 Print view | E-mail friend Previous topic | Next topic
Author Message
 Post subject: Roots of rational polynomialsPosted: Mon Apr 24, 2017 8:49 am

Joined: Sat Feb 18, 2017 10:08 am
Posts: 5
Consider this code:

Code:
ring A=0,x,lp;
poly f=(x-3/17)*(x+2/3);

I don't see a straightforward way to find the exact (as rational numbers) roots of f. I looked a bit at the documentation and if I use the command laguerre(f,5,1), I obtain roots up to 5 digits (decimal) precision and not really the rational roots 3/17 and -2/3. Of course I can use factorize(f) and write a code that extracts the rational roots, but I am sure (I hope) there is a cleaner way to do this. Any hints would be much appreciated. Thanks!

Top

 Post subject: Re: Roots of rational polynomialsPosted: Mon Apr 24, 2017 9:36 am

Joined: Sat Feb 18, 2017 10:08 am
Posts: 5
So far I am using this procedure. It could exist in some library already?

Code:
//rational roots of a rational polynomial
proc Qroots(poly f)
{
ideal l = factorize(f,1);
list ret;
for (int i=1;i<=size(l);i++)
{
if (deg(l[i])==1)
{ //roots are rational
if (size(l[i])==1) { ret=ret+list(0);}
}
}
return(ret);
}

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 2 posts ]

 You can post new topics in this forumYou can reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

 It is currently Sat Dec 15, 2018 9:18 pm