Martin Rubey wrote:
> I tried to demonstrate Cayley Hamilton in Sage, but failed. Here is what I
> tries:
>
> sage: f = function('f')
> sage: m = matrix([[f(i,j) for j in range(2)] for i in range(2)])
> sage: p=SR[x](m.characteristic_polynomial('x'))
> sage: p.subs(x=m)
>
> [(f(0, 0) - x)*(f(1, 1) - x) - f(0, 1)*f(1, 0)
> 0]
> [ 0 (f(0, 0) - x)*(f(1, 1) - x) -
> f(0, 1)*f(1, 0)]
>
> Of course, the result *should* be the zero matrix. It seems that the value of
> p is not what I'd expect:
>
> sage: p.coefficients()
> [(f(0, 0) - x)*(f(1, 1) - x) - f(0, 1)*f(1, 0)]
>
> So, probably the question is: how do I create a polynomial over Symbolic Ring
> properly?
To answer your original question:
sage: f = function('f')
sage: m = matrix([[f(i,j) for j in range(2)] for i in range(2)])
sage: p=m.charpoly('x')
sage: p
(f(0, 0) - x)*(f(1, 1) - x) - f(0, 1)*f(1, 0)
sage: p.coefficients(x)
[[f(0, 0)*f(1, 1) - f(0, 1)*f(1, 0), 0], [-f(1, 1) - f(0, 0), 1], [1, 2]]
However, we run into problems. Any comments on these, anyone?
sage: p.subs(x=m)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/home/jason/<ipython console> in <module>()
/home/jason/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.pyc
in subs(self, *args, **kwds)
3703
3704 def subs(self, *args, **kwds):
-> 3705 return self.substitute(*args, **kwds)
3706
3707 def _recursive_sub(self, kwds):
/home/jason/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.pyc
in substitute(self, in_dict, **kwds)
3700 kwds = self.__parse_in_dict(in_dict, kwds)
3701 kwds = self.__varify_kwds(kwds)
-> 3702 return X._recursive_sub(kwds)
3703
3704 def subs(self, *args, **kwds):
/home/jason/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.pyc
in _recursive_sub(self, kwds)
4752 """
4753 ops = self._operands
-> 4754 new_ops = [SR(op._recursive_sub(kwds)) for op in ops]
4755
4756 #Check to see if all of the new_ops are symbolic constants
/home/jason/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.pyc
in _recursive_sub(self, kwds)
4752 """
4753 ops = self._operands
-> 4754 new_ops = [SR(op._recursive_sub(kwds)) for op in ops]
4755
4756 #Check to see if all of the new_ops are symbolic constants
/home/jason/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.pyc
in _recursive_sub(self, kwds)
4752 """
4753 ops = self._operands
-> 4754 new_ops = [SR(op._recursive_sub(kwds)) for op in ops]
4755
4756 #Check to see if all of the new_ops are symbolic constants
/home/jason/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.pyc
in __call__(self, x)
452 msg, s, pos = err.args
453 raise TypeError, "%s: %s !!! %s" % (msg,
s[:pos], s[pos:])
--> 454 return self._coerce_impl(x)
455
456 def _coerce_impl(self, x):
/home/jason/sage/local/lib/python2.5/site-packages/sage/calculus/calculus.pyc
in _coerce_impl(self, x)
508 return self(x._sage_())
509 else:
--> 510 raise TypeError, "cannot coerce type '%s' into a
SymbolicExpression."%type(x)
511
512 def _repr_(self):
TypeError: cannot coerce type '<type
'sage.matrix.matrix_symbolic_dense.Matrix_symbolic_dense'>' into a
SymbolicExpression.
--~--~---------~--~----~------------~-------~--~----~
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
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---