Contents Changes to MuPAD 1.2.2 Advanced Calculus Polynomials Linear Algebra Graphics Gröbner Bases Further Nice Examples
Cat::CommutativeRing
Cat::Ring
Dom::DistributedPolynomial
Dom::ExpressionField
Dom::Fraction
Dom::Integer
Dom::Rational
Dom::SquareMatrix
domains
exp
invert
linalg
linalg::det
linalg::eigenVectors
linalg::jordanForm
linalg::ogSystem
linalg::scalarProduct
linalg::sylvester
norm
The following statement creates the ring of 3-rows square matrices over the ring of polynomials:
>> MP:= Dom::SquareMatrix( 3, Dom::Polynomial(Dom::Integer) );
Dom::SquareMatrix(3, Dom::Polynomial(Dom::Integer))
>> MP::hasProp( Cat::Ring ), MP::hasProp( Cat::CommutativeRing );
TRUE, FALSEThe domain constructors
Dom::SquareMatrix
,
Dom::DistributedPolynomial
and
Dom::Integer
such as the categories Cat::Ring
and Cat::CommutativeRing
are part of the domains
library.
Now we are able to create matrices and to perform some calculations involving matrices:
>> A:= MP( [[0,y,1], [0,x^2,0], [y^3,0,y^5]] );
+- -+ | 0, y, 1 | | | | 2 | | 0, x , 0 | | | | 3 5 | | y , 0, y | +- -+
>> B:= MP( [x,1,y], Diagonal );
+- -+ | x, 0, 0 | | | | 0, 1, 0 | | | | 0, 0, y | +- -+
Matrix arithmetic can be performed by using the standard arithmetical operators of MuPAD:
>> A * B - B * A;
+- -+ | 0, y - x y, - x + y | | | | 0, 0, 0 | | | | 4 3 | | - y + x y , 0, 0 | +- -+
>> ( A + B )^2;
+- -+ | 2 3 2 5 | | x + y , y + x y + x y, x + y + y | | | | 2 4 | | 0, 2 x + x + 1, 0 | | | | 4 8 3 4 2 3 6 10 | | y + y + x y , y , y + y + 2 y + y | +- -+
Matrix is not invertible, as we can see by
>> 1/A;
FAILBut if we consider the matrix A to be defined over the fraction field of its coefficient domain:
>> Af:= Dom::Matrix(Dom::Fraction(A::coeffRing))( A );
+- -+ | 0, y, 1 | | | | 2 | | 0, x , 0 | | | | 3 5 | | y , 0, y | +- -+then the inverse of this matrix can be computed:
>> Af^(-1);
+- -+ | 3 | | 2 y 1 | | - y , --, -- | | 2 3 | | x y | | | | 1 | | 0, --, 0 | | 2 | | x | | | | y | | 1, - --, 0 | | 2 | | x | +- -+
>> Af * %, % * Af;
+- -+ +- -+ | 1, 0, 0 | | 1, 0, 0 | | | | | | 0, 1, 0 |, | 0, 1, 0 | | | | | | 0, 0, 1 | | 0, 0, 1 | +- -+ +- -+
Let us now consider matrices defined over arbitrary arithmetical expressions, which is even the standard coefficient domain for matrices:
>> M:= Dom::Matrix();
Dom::Matrix(Dom::ExpressionField(id, iszero))
If we want to compute the exponential of the matrix
>> A:= M( [[-13,-10],[21,16]] );
+- -+ | -13, -10 | | | | 21, 16 | +- -+we just type in the statement
>> exp( A,t );
+- -+ | 15 exp(t) - 14 exp(2 t), 10 exp(t) - 10 exp(2 t) | | | | - 21 exp(t) + 21 exp(2 t), - 14 exp(t) + 15 exp(2 t) | +- -+
It is likewise easily to compute a norm of the matrix , so for example the infinity-norm and the Frobenius-norm:
>> norm( A ), norm( A,Frobenius );
1/2 37, 966
linalg
consists of many functions for doing linear algebra
with MuPAD. To export all of its functions, use:
>> export(linalg):
Warning: 'trace' already has a value, not exported
Let us define the matrix
>> A:= Dom::Matrix(Dom::Rational)( [[1,-3,3], [3,-5,3], [6,-6,4]] );
+- -+ | 1, -3, 3 | | | | 3, -5, 3 | | | | 6, -6, 4 | +- -+over the rationals. Its eigensystem is given by
>> eigenVectors( A );
-- -- -- +- -+ +- -+ -- -- -- -- +- -+ -- -- -- | | | | 1 | | -1 | | | | | | 1/2 | | | | | | | | | | | | | | | | | | | | | | -2, 2, | | 1 |, | 0 | | |, | 4, 1, | | 1/2 | | | | | | | | | | | | | | | | | | | | | | | | 0 | | 1 | | | | | | 1 | | | | -- -- -- +- -+ +- -+ -- -- -- -- +- -+ -- -- --
and the diagonalization of A leads to a matrix like
>> jordanForm( A );
+- -+ | -2, 0, 0 | | | | 0, -2, 0 | | | | 0, 0, 4 | +- -+that also could be determined by the already computed eigensystem of A.
We give a small example to compute the determinant of a matrix over a commutative ring:
>> A := randomMatrix( 2,2,Dom::DistributedPolynomial([x],Dom::IntegerMod(6)) );
+- -+ | 2 2 3 | | 2 x , 3 x - 2 x + 2 x | | | | 2 4 5 3 5 | | x + 3 x - x + 3, 2 x - x + 1 | +- -+The output may be different to yours, because we have create this matrix randomly.
>> det( A );
2 3 4 5 6 7 8 3 x + 2 x + 3 x + 2 x - x + 3 x + 2 x + 2 x
An easy (but of course not an efficient) way to determine the resultant of the two polynomials
>> f := poly( 1+2*x+10*x^2, IntMod(7) ); g := poly( x^2+23*x-5, IntMod(7) );
2 poly(2 x + 3 x + 1, [x], IntMod(7)) 2 poly(2 x + x + 2, [x], IntMod(7))
is to compute the determinant of the corresponding Sylvester matrix:
>> det( sylvester( f,g,x ) );
3 mod 7
It is possible to compute a set of orthonormal vectors
with respect to the scalar product defined by the
function linalg::scalarProduct
from a given list of linearly independent vectors over a field.
Consider the following exercise:
We redefine the function linalg::scalarProduct
to be
>> sysassign( linalg::scalarProduct, proc(f,g) local F, R, t; begin R := f::coeffRing; F := int( expr(f[1])*expr(g[1]), t=0..1 ); R(F) end_proc ):Note that we have to force this assignment because standardly the identifier
linalg
is write protected.
We then create the matrix which consits of the first five polynomials:
>> A := Dom::Matrix()( [[1, t, t^2, t^3, t^4]] );
2 3 4 [1, t, t , t , t ]
Then by the function linalg::ogSystem
the orthogonalization process will be performed on the columns
of A:
>> S:= ogSystem( col(A,1..4) );
-- | | +- -+ +- -+ +- 2 -+ | | 1 |, | t - 1/2 |, | - t + t + 1/6 |, | +- -+ +- -+ +- -+ -- +- -+ -- | 2 | | | 3 t 3 t 3 | | | --- - ---- + t - 1/20 | | | 5 2 | | +- -+ --
We can normalize the vectors of S
by
>> map( S, normalize );
-- | | +- -+ +- 1/2 -+ +- 1/2 2 -+ | | 1 |, | 12 (t - 1/2) |, | 180 (- t + t + 1/6) |, | +- -+ +- -+ +- -+ -- +- -+ -- | / 2 \ | | | 1/2 | 3 t 3 t 3 | | | | 2800 | --- - ---- + t - 1/20 | | | | \ 5 2 / | | +- -+ --
Finally we give an example to compute the Cholesky factorization of a matrix, which additionally gives us the information that the matrix is positive definite:
>> S:= Dom::Matrix(Dom::Rational)( [[4,-2,4,2], [-2,10,-2,-7], [4,-2,8,4], [2,-7,4,7]] );
+- -+ | 4, -2, 4, 2 | | | | -2, 10, -2, -7 | | | | 4, -2, 8, 4 | | | | 2, -7, 4, 7 | +- -+
>> linalg::cholesky( S );
+- -+ | 2, 0, 0, 0 | | | | -1, 3, 0, 0 | | | | 2, 0, 2, 0 | | | | 1, -2, 1, 1 | +- -+