On Feb 18, 12:24 pm, Thomas Arildsen <[email protected]> wrote:
> Does Sage have functions for building matrices corresponding to the
> Matlab functions toeplitz and/or hankel?
>
> Thomas Arildsen
Hi Thomas
Sage wraps numpy, and numpy has support. Matrix arrays can be
exchanged, too. Note, that you have to specify the type with dtype
since there is a preparser - otherwise append an "r" to each number.
first import:
sage: import numpy as np
sage: import scipy.linalg as la
matlab examples from the help:
sage: c = np.r_[1:4]
sage: r = np.r_[7:11]
sage: la.hankel(c,r)
Warning: column and row values don't agree; column value used.
array([[ 1, 2, 3, 8],
[ 2, 3, 8, 9],
[ 3, 8, 9, 10]])
sage: c = np.array([1 , 2 , 3 , 4 , 5], dtype=float);
sage: r = np.array([1.5 , 2.5 , 3.5, 4.5, 5.5], dtype=float);
sage: a = la.toeplitz(c,r); a
Warning: column and row values don't agree; column value used.
array([[ 1. , 2.5, 3.5, 4.5, 5.5],
[ 2. , 1. , 2.5, 3.5, 4.5],
[ 3. , 2. , 1. , 2.5, 3.5],
[ 4. , 3. , 2. , 1. , 2.5],
[ 5. , 4. , 3. , 2. , 1. ]])
matrix as a sage type (variable a above):
sage: type(matrix(a))
<type 'sage.matrix.matrix_integer_dense.Matrix_integer_dense'>
h
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---