On Mar 1, 3:02 am, Alex Ghitza <aghi...@gmail.com> wrote:
> On Sun, 28 Feb 2010 23:02:08 -0800 (PST), Sharpie <ch...@sharpsteen.net> 
> wrote:
> > However, tonight I have been trying to solve an open channel flow
> > problem which requires me to find the roots of:
>
> >   y^3 - 1.39027132807289 * y^2 + 0.090610488164005 == 0
>
> > find_root() does return the correct answers-- but in this case both
> > positive roots are of interest so it would be nice to recover them
> > both at the same time.
>
> Hi,
>
> How about this:
>
> sage: R.<y> = RR[]
> sage: f = y^3 - 1.39027132807289 * y^2 + 0.090610488164005
> sage: f.roots()
> [(-0.236040904804615, 1), (0.286518993973450, 1), (1.33979323890405, 1)]
>
> Is this what you were hoping for?
>
> Best,
> Alex
>
> --
> Alex Ghitza --http://aghitza.org/
> Lecturer in Mathematics -- The University of Melbourne -- Australia

Thanks for the reply Alex. I think I understand that by choosing a
variable of the appropriate type, in this case one that is restricted
to the real numbers, the roots can be determined in a straight-forward
manner.

I had some more problems, but finally figured out how to coerce a
expression of type symbolic to the real ring through a somewhat
convoluted application of multiplication, full_simplify() and
polynomial().

The cubic is the result of balancing a system of conservation
equations and then substituting in known information:

y2 = var( 'y2' )

f  =  1.54027132807289 == y2 + 0.0906104881640050/y2^2 +
0.150000000000000

# Multiply to eliminate fractions.
f  = f * y2^2

f.full_simplify().polynomial(RR).roots()

[(-0.236040904804615, 1), (0.286518993973450, 1), (1.33979323890405,
1)]


That gives the correct answer-- but it seems pretty darn inelegant,
distracted and burdensome to explain when presented in a homework
report.  I experimented with the "domain=" argument to var() to see if
it could help, but I didn't notice any changes.

If someone could suggest a way the above code could be cleaned up, I
would be very grateful!

-Charlie

-- 
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to