This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Compute with Matrices

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

Basic Arithmetic Operations

When performing basic arithmetic operations on matrices, use the standard arithmetic operators. For example, add, subtract, multiply, and divide the following two matrices by using the standard +, -, *, and / operators:

A := matrix([[a, b], [c, d]]):
B := matrix([[1, 2], [3, 4]]):
A + B, A - B, A*B, A/B

To perform basic operations on a matrix and a number, use the same operators. When you multiply a matrix by a number, MuPAD® multiplies all elements of a matrix by that number:


When you add a number to a matrix, MuPAD multiplies the number by an identity matrix, and then adds the result to the original matrix:

A + 5


MATLAB® adds a number to each element of a matrix. MuPAD adds a number only to the diagonal elements of a matrix.

You can combine matrices with the same number of rows by using the concatenation operator (.):


More Operations Available for Matrices

Besides standard arithmetic operations, many other MuPAD functions are available for computations involving matrices and vectors. To check whether a particular function accepts matrices as parameters, see the “Parameters” section of the function help page. The following functions can operate on matrices:

  • The conjugate function computes the conjugate of each complex element of a matrix:

    A := matrix([[1, 2 + 3*I], [1 - I, 2*I]]):

  • The int and diff functions compute the derivative and the integral of each element of a matrix:

    A := matrix(2, 2, [x, x^2, x^3, x^4]):
    int(A, x), diff(A, x)

  • The expand function expands each element of a matrix:

    A := matrix(2, 2, [x, (x + 1)^2, x*(x - 1), x*(x + 4)]):

  • The map function applies the specified function to all operands of each element of a matrix:

    A := matrix(3, 3, [1, 2, 3], Diagonal):
    B := map(A, sin)

  • The float function converts each element of a matrix or numerical subexpressions of each element of a matrix to floating-point numbers:


  • The evalAt function (and its shortcut |) substitutes the specified object by another specified object, and then evaluates each element of a matrix:

    A := matrix(2, 2, [x, x^2, x^3, x^4]):
    A|x = 2

  • The subs function returns a copy of a matrix in which the specified object replaces all instances of another specified object. The function does not evaluate the elements of a matrix after substitution:

    A := matrix(2, 2, [x, x^2, x^3, x^4]):
    subs(A, x = exp(y))

  • The has function determines whether a matrix contains the specified object:

    A := matrix(2, 2, [x, x^2, x^3, x^4]):
    has(A, x^3), has(A, x^5)

  • The iszero function checks whether all elements of a matrix are zeros:

    A := matrix(2, 2):

    A[1, 1] := 1:

  • The norm function computes the infinity norm (row sum norm) of a matrix:

    A := matrix(2, 2, [a_1_1, a_1_2, a_2_1, a_2_2]):

  • The zip(A, B, f) function combines matrices A and B into a matrix C so that Cij = f(Aij, Bij):

    A := matrix(2, 2, [a, b, c, d]):
    B := matrix(2, 2, [10, 20, 30, 40]):
    zip(A, B, _power)

Was this topic helpful?