Re: [sage-support] Re: Is sage 4.3.5 able to solve quadratic equations??
On Jun 21, 2010, at 10:53 PM, Matthias Meulien wrote: I guess that the problem comes from the type of p1, not being an Expression. So is it possible to cast this p1 to the Expression class? A direct conversion like the following works: sage: p3 = 0 sage: for c in p1.coeffs(): : p3 = x*p3 + c : sage: p3 -3/4*pi + 7/4*pi*x sage: type(p3) type 'sage.symbolic.expression.Expression' sage: p3.roots(x) [(3/7, 1)] You could evaluate p1 at the symbolic variable x. sage: basering = PolynomialRing(SR, 'x') sage: p1 = basering.lagrange_polynomial([(0,0), (1,pi), (2, pi/2)]) sage: expr = p1(var('x')) sage: type(expr) type 'sage.symbolic.expression.Expression' sage: expr.roots(x) [(7/3, 1), (0, 1)] - Robert -- 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
[sage-support] Re: Is sage 4.3.5 able to solve quadratic equations??
Thanks for helping. I am trying to compute (not numericaly!) the roots of a quadratic equation build from lagrange_polynomial()... sage: p2 = SR(-3/4*pi)*x^2 + SR(7/4*pi)*x sage: p2.roots(x) [(7/3, 1), (0, 1)] Now we are back to the original question: Why the following rise a type error?? I guess that the problem comes from the type of p1, not being an Expression. So is it possible to cast this p1 to the Expression class? sage: SR(-3/4*pi)*x^2 + SR(7/4*pi)*x sage: basering = PolynomialRing(SR, 'x') sage: p1 = basering.lagrange_polynomial([(0,0), (1,pi), (2, pi/2)]) sage: p1 -3/4*pi*x^2 + 7/4*pi*x sage: p1.roots(x) (...) TypeError Traceback (most recent call last) (...) TypeError: base_ring must be a ring -- 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
[sage-support] Re: Is sage 4.3.5 able to solve quadratic equations??
I guess that the problem comes from the type of p1, not being an Expression. So is it possible to cast this p1 to the Expression class? A direct conversion like the following works: sage: p3 = 0 sage: for c in p1.coeffs(): : p3 = x*p3 + c : sage: p3 -3/4*pi + 7/4*pi*x sage: type(p3) type 'sage.symbolic.expression.Expression' sage: p3.roots(x) [(3/7, 1)] -- 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
[sage-support] Re: Is sage 4.3.5 able to solve quadratic equations??
Thanks for helping. I am trying to compute (not numericaly!) the roots of a quadratic equation build from lagrange_polynomial()... sage: p2 = SR(-3/4*pi)*x^2 + SR(7/4*pi)*x sage: p2.roots(x) [(7/3, 1), (0, 1)] Now we are back to the original question: Why the following rise a type error?? I guess that the problem comes from the type of p1, not being an Expression. So is it possible to cast this p1 to the Expression class? sage: SR(-3/4*pi)*x^2 + SR(7/4*pi)*x sage: basering = PolynomialRing(SR, 'x') sage: p1 = basering.lagrange_polynomial([(0,0), (1,pi), (2, pi/2)]) sage: p1 -3/4*pi*x^2 + 7/4*pi*x sage: p1.roots(x) (...) TypeError Traceback (most recent call last) (...) TypeError: base_ring must be a ring -- 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
[sage-support] Re: Is sage 4.3.5 able to solve quadratic equations??
It works for me in Sage 4.3.3 and in 4.4.2. -- | Sage Version 4.3.3, Release Date: 2010-02-21 | | Type notebook() for the GUI, and license() for information.| -- sage: basering = PolynomialRing(SR, 'x') sage: polynomial = basering.lagrange_polynomial([(0,0), (1,pi), (2, pi/ : 2)]) sage: polynomial -3/4*pi*x^2 + 7/4*pi*x Matthias Meulien wrote: Hi, I can't figure out why the following commands ends with a TypeError exception. sage: basering = PolynomialRing(SR, 'x') sage: polynomial = basering.lagrange_polynomial([(0,0), (1,pi), (2, pi/ 2)]) sage: polynomial.base_ring() Symbolic Ring sage: type(polynomial) class 'sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_dense_field' sage: polynomial.roots(x) --- TypeError Traceback (most recent call last) /home/matthias/ipython console in module() /home/matthias/Sources/sage-4.3.5/local/lib/python2.6/site-packages/ sage/rings/polynomial/polynomial_element.so in sage.rings.polynomial.polynomial_element.Polynomial.roots (sage/rings/ polynomial/polynomial_element.c:29945)() /home/matthias/Sources/sage-4.3.5/local/lib/python2.6/site-packages/ sage/rings/polynomial/polynomial_element.so in sage.rings.polynomial.polynomial_element.Polynomial.change_ring (sage/ rings/polynomial/polynomial_element.c:15968)() /home/matthias/Sources/sage-4.3.5/local/lib/python2.6/site-packages/ sage/rings/polynomial/polynomial_ring.pyc in change_ring(self, R) 606 from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing 607 -- 608 return PolynomialRing(R, names=self.variable_name(), sparse=self.is_sparse()) 609 610 def change_var(self, var): /home/matthias/Sources/sage-4.3.5/local/lib/python2.6/site-packages/ sage/rings/polynomial/polynomial_ring_constructor.pyc in PolynomialRing(base_ring, arg1, arg2, sparse, order, names, name, implementation) 317 318 if not m.ring.is_Ring(base_ring): -- 319 raise TypeError, 'base_ring must be a ring' 320 321 if arg1 is None: TypeError: base_ring must be a ring Thanks for reading. -- 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
[sage-support] Re: Is sage 4.3.5 able to solve quadratic equations??
On 21 juin, 08:56, Wilfried Huss h...@finanz.math.tugraz.at wrote: It works for me in Sage 4.3.3 and in 4.4.2. You mean the call to polynomial.roots(x) did not launch any exceptions? It is not clear from your answer: I can't find a call to polynomial.roots(x) in your session... -- 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
[sage-support] Re: Is sage 4.3.5 able to solve quadratic equations??
On Jun 20, 6:50 pm, Matthias Meulien oron...@gmail.com wrote: Hi, I can't figure out why the following commands ends with a TypeError exception. sage: basering = PolynomialRing(SR, 'x') sage: polynomial = basering.lagrange_polynomial([(0,0), (1,pi), (2, pi/ 2)]) sage: polynomial.base_ring() Symbolic Ring sage: type(polynomial) class 'sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_dense_field' sage: polynomial.roots(x) ~ snip ~ TypeError: base_ring must be a ring Thanks for reading. sage: polynomial.roots? gives lots of information including the calling information: polynomial.roots(self, ring=None, multiplicities=True, algorithm =None) It appears that a ring is needed. If I do sage: polynomial.roots(RR) [(0.000, 1), (2.33, 1)] There may be more information in the doc string that is useful for you. HTH, Adam -- 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