On Tue, 2 Mar 2010 05:27:45 -0800 (PST), Sharpie <[email protected]> wrote:
> 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.

The way I see it, it is not actually a question about the variable
representing a real number; it is more a question of using polynomials
and their specialised built-in roots() method rather than symbolic
functions and the general-purpose solve().

> 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)]

There might be an elegant way of doing this with symbolics, but I don't
know it.  However, if I move everything to one side of the == sign, your
f is a rational function (quotient of polynomials with real
coefficients).  So my approach would be:

sage: R.<y2> = RR[]               # polynomials in y2 with real coefficients
sage: f = y2 + 0.0906104881640050/y2^2 + 0.150000000000000 - 1.54027132807289
sage: f.numerator().roots()
[(-0.236040904804615, 1), (0.286518993973450, 1), (1.33979323890405, 1)]

Note that the first line tells Sage what y2 is: the variable in a
polynomial ring with real coefficients.  Then when you define f, Sage
automatically knows that f is a rational function (in particular, it's
not an element of R, but of the fraction field of R:
sage: parent(f)
Fraction Field of Univariate Polynomial Ring in y2 over Real Field with 53 bits 
of precision
)

Anyway, I think it would make perfect sense to be able to just do
f.roots() for a rational function and have this return the roots of the
numerator, so that would make this a bit nicer.  For that matter, I
think that for a rational function f we should have both f.zeroes() and
f.poles() (and maybe also f.divisor()), and have f.roots() be an alias
for f.zeroes().

And again, maybe there should be a nice way of doing this within
symbolics and somebody else can comment on this.


Best,
Alex

-- 
Alex Ghitza -- http://aghitza.org/
Lecturer in Mathematics -- The University of Melbourne -- Australia

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

Reply via email to