Norbert's solution is short but unfortunately for nth_real_root(4,2)
gives a result of -2 instead of what the TC MITS expected result of 2.
One slight modification handles that issue to give results that match these
expectations- Unfortunately- this function doesn't seem to plot!???:
def nth_real_root(a,n):
p = x^n - a
L = p.roots(ring=RR,
multiplicities=False)
if L:
return sgn(a)*sgn(L[0])*L[0] # return L ?
else:
raise RuntimeError("no real root")
ALSO-
On naming the function: eventually a shorter name would be helpful if this
is to become a core real function:
perhaps r_rootn(x,n) or simply rootn(x,n).
>From a foggy morning in Arcata,
Martin Flashman
On Monday, July 14, 2014 1:13:55 PM UTC-7, Norbert Domes wrote:
>
> My suggestion for nth real root:
>
>
>
> def nth_real_root(a,n):
>
> p = x^n - a
> L = p.roots(ring=RR,multiplicities=False)
> if L:
> return L[0] # return L ?
> else:
> raise RuntimeError("no real root")
>
--
You received this message because you are subscribed to the Google Groups
"sage-edu" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-edu.
For more options, visit https://groups.google.com/d/optout.