08.02.2015 Views

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

Sage Reference Manual: Matrices and Spaces of Matrices - Mirrors

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Sage</strong> <strong>Reference</strong> <strong>Manual</strong>: <strong>Matrices</strong> <strong>and</strong> <strong>Spaces</strong> <strong>of</strong> <strong>Matrices</strong>, Release 6.1.1<br />

See Also:<br />

smith_form()<br />

elementwise_product(right)<br />

Returns the elementwise product <strong>of</strong> two matrices <strong>of</strong> the same size (also known as the Hadamard product).<br />

INPUT:<br />

•right - the right oper<strong>and</strong> <strong>of</strong> the product. A matrix <strong>of</strong> the same size as self such that multiplication<br />

<strong>of</strong> elements <strong>of</strong> the base rings <strong>of</strong> self <strong>and</strong> right is defined, once <strong>Sage</strong>’s coercion model is applied.<br />

If the matrices have different sizes, or if multiplication <strong>of</strong> individual entries cannot be achieved, a<br />

TypeError will result.<br />

OUTPUT:<br />

A matrix <strong>of</strong> the same size as self <strong>and</strong> right. The entry in location (i, j) <strong>of</strong> the output is the product <strong>of</strong><br />

the two entries in location (i, j) <strong>of</strong> self <strong>and</strong> right (in that order).<br />

The parent <strong>of</strong> the result is determined by <strong>Sage</strong>’s coercion model. If the base rings are identical, then the<br />

result is dense or sparse according to this property for the left oper<strong>and</strong>. If the base rings must be adjusted<br />

for one, or both, matrices then the result will be sparse only if both oper<strong>and</strong>s are sparse. No subdivisions<br />

are present in the result.<br />

If the type <strong>of</strong> the result is not to your liking, or the ring could be “tighter,” adjust the oper<strong>and</strong>s with<br />

change_ring(). Adjust sparse versus dense inputs with the methods sparse_matrix() <strong>and</strong><br />

dense_matrix().<br />

EXAMPLES:<br />

sage: A = matrix(ZZ, 2, range(6))<br />

sage: B = matrix(QQ, 2, [5, 1/3, 2/7, 11/2, -3/2, 8])<br />

sage: C = A.elementwise_product(B)<br />

sage: C<br />

[ 0 1/3 4/7]<br />

[33/2 -6 40]<br />

sage: C.parent()<br />

Full MatrixSpace <strong>of</strong> 2 by 3 dense matrices over Rational Field<br />

Notice the base ring <strong>of</strong> the results in the next two examples.<br />

sage: D = matrix(ZZ[x],2,[1+x^2,2,3,4-x])<br />

sage: E = matrix(QQ,2,[1,2,3,4])<br />

sage: F = D.elementwise_product(E)<br />

sage: F<br />

[ x^2 + 1 4]<br />

[ 9 -4*x + 16]<br />

sage: F.parent()<br />

Full MatrixSpace <strong>of</strong> 2 by 2 dense matrices over Univariate Polynomial Ring in x over Rational<br />

sage: G = matrix(GF(3),2,[0,1,2,2])<br />

sage: H = matrix(ZZ,2,[1,2,3,4])<br />

sage: J = G.elementwise_product(H)<br />

sage: J<br />

[0 2]<br />

[0 2]<br />

sage: J.parent()<br />

Full MatrixSpace <strong>of</strong> 2 by 2 dense matrices over Finite Field <strong>of</strong> size 3<br />

Non-commutative rings behave as expected. These are the usual quaternions.<br />

167

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!