Home | Trees | Index | Help |
|
---|
Package sage :: Package linalg :: Module vector_space :: Class VectorSpace |
|
object
--+
|
VectorSpace
VectorSpace_generic
Create a Vector Space. Two create an ambient space over a field with given dimension using the calling syntax VectorSpace(field, dimension, sparse=True) and to create a subspace use VectorSpace(list_of_vectors), where list_of_vectors is a list of vectors in a VectorSpace. EXAMPLES: First we create some ambient spaces. >>> from sage.rings.rings import RationalField, CyclotomicField >>> V = VectorSpace(RationalField(), 389); V Full Vector space of degree 389 over Rational Field >>> V.dimension() 389 >>> K = CyclotomicField(7) >>> VK = VectorSpace(K, 3); VK Full Vector space of degree 3 over Cyclotomic Field of order 7 and degree 6 >>> K.gen(0)*VK.gen(1) (0 zeta_7 0) Next we create some subspaces. >>> W = VectorSpace([VK.gen(1) + K.gen(0)*VK.gen(2)]); W Vector space of degree 3, dimension 1 over Cyclotomic Field of order 7 and degree 6 Basis matrix: [ 0 1 zeta_7] >>> V = VectorSpace(RationalField(), 3) >>> W = VectorSpace([V.gen(0)]); W Vector space of degree 3, dimension 1 over Rational Field Basis matrix: [1 0 0] >>> v0 = V([1,2,3]) >>> v1 = V([4,5,6]) >>> v2 = V([7,8,9]) >>> W = VectorSpace([v0,v1,v2]); W Vector space of degree 3, dimension 2 over Rational Field Basis matrix: [ 1 0 -1] [ 0 1 2] We illustrate most of the functions on an ambient space: >>> V = VectorSpace(RationalField(), 3) >>> V.ambient_space() Full Vector space of degree 3 over Rational Field >>> V == V.ambient_space() True >>> V == VectorSpace(CyclotomicField(3), 3) False >>> V.base_field() Rational Field >>> V.basis() [(1 0 0), (0 1 0), (0 0 1)] >>> V.coordinates(V._0 + 2*V._1 - 3*V._2) [1, 2, -3] >>> V.degree() 3 >>> V.dimension() 3 >>> V.gen(0) (1 0 0) >>> V.is_dense() True >>> V.is_sparse() False >>> V.matrix() [1 0 0] [0 1 0] [0 0 1] >>> V.ngens() 3 >>> V.random_element() in V True >>> V.vector([1,2,3]) (1 2 3) >>> V.vector_space(100) Full Vector space of degree 100 over Rational Field >>> V.zero_vector() (0 0 0) We create a sparse ambient vector space, and demonstrate each of the above functions on it. >>> V = VectorSpace(RationalField(), 3, sparse=True) >>> V.ambient_space() Full Vector space of degree 3 over Rational Field >>> V == V.ambient_space() True >>> V == VectorSpace(CyclotomicField(3), 3) False >>> V.base_field() Rational Field >>> V.basis() [(1 0 0), (0 1 0), (0 0 1)] >>> V.coordinates(V._0 + 2*V._1 - 3*V._2) [1, 2, -3] >>> V.degree() 3 >>> V.dimension() 3 >>> V.gen(0) (1 0 0) >>> V.is_dense() False >>> V.is_sparse() True >>> V.matrix() [1 0 0] [0 1 0] [0 0 1] >>> V.matrix().is_sparse() True >>> V.ngens() 3 >>> V.random_element() in V True >>> v = V.vector([1,2,3]); v (1 2 3) >>> v.is_sparse() True >>> W = V.vector_space(100); W Full Vector space of degree 100 over Rational Field >>> W.is_sparse() True We create a subspace of a dense vector space, and illustrate each function on it: >>> V0 = VectorSpace(RationalField(), 3) >>> V = VectorSpace([V0([1,2,3]), V0([4,5,6]), V0([7,8,9])]); V Vector space of degree 3, dimension 2 over Rational Field Basis matrix: [ 1 0 -1] [ 0 1 2] >>> V.ambient_space() Full Vector space of degree 3 over Rational Field >>> V == V.ambient_space() False >>> V.base_field() Rational Field >>> V.generators() [(1 2 3), (4 5 6), (7 8 9)] >>> V.coordinates(V([1, 0, -1])) [1, 0] >>> V.coordinates(V([1, 0, 0])) Traceback (most recent call last): ... ArithmeticError: v is not in self >>> V.degree() 3 >>> V.dimension() 2 Note that the ith generator of a subspace is not the ith element of the list of vectors that generators, but is the free generator, i.e., the ith basis vector. >>> w = V.gen(0); w (1 0 -1) >>> w.is_sparse() False >>> V.is_dense() True >>> V.matrix() [ 1 0 -1] [ 0 1 2] >>> V.matrix().is_sparse() False >>> V.ngens() 2 >>> V.random_element() in V True >>> V.vector([1,2,3]) (1 2 3) >>> V([1,2,3]) (1 2 3) >>> V.vector([1,0,0]) Traceback (most recent call last): ... ArithmeticError: v is not in self >>> V.zero_vector() (0 0 0) We create a subspace of a sparse vector space, and illustrate each function on it: >>> V0 = VectorSpace(RationalField(), 3, sparse =True) >>> V0.is_sparse() True >>> V = VectorSpace([V0([1,2,3]), V0([4,5,6]), V0([7,8,9])]); V Vector space of degree 3, dimension 2 over Rational Field Basis matrix: [ 1 0 -1] [ 0 1 2] >>> V.is_sparse() True >>> V.ambient_space() Full Vector space of degree 3 over Rational Field >>> V == V.ambient_space() False >>> V.base_field() Rational Field >>> V.generators() [(1 2 3), (4 5 6), (7 8 9)] >>> V.coordinates(V([1, 0, -1])) [1, 0] >>> V.coordinates(V([1, 0, 0])) Traceback (most recent call last): ... ArithmeticError: v is not in self >>> V.degree() 3 >>> w = V.gen(0); w (1 0 -1) >>> w.is_sparse() True >>> V.is_dense() False >>> V.matrix() [ 1 0 -1] [ 0 1 2] >>> V.matrix().is_sparse() True >>> V.ngens() 2 >>> V.random_element() in V True >>> V.vector([1,2,3]) (1 2 3) >>> V.vector([1,0,0]) Traceback (most recent call last): ... ArithmeticError: v is not in self >>> V.zero_vector() (0 0 0)
Method Summary | |
---|---|
__init__(self,
*args,
**kwds)
| |
__new__(cls,
*args,
**kwds)
(Static method) | |
Inherited from object | |
x.__delattr__('name') <==> del x.name | |
x.__getattribute__('name') <==> x.name | |
x.__hash__() <==> hash(x) | |
helper for pickle | |
helper for pickle | |
x.__repr__() <==> repr(x) | |
x.__setattr__('name', value) <==> x.name = value | |
x.__str__() <==> str(x) |
Home | Trees | Index | Help |
|
---|
Generated by Epydoc 2.1 on Mon May 9 17:57:02 2005 | http://epydoc.sf.net |