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.


Linear combination of matrix rows

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.


linalg::addRow(A, r1, r2, s)
linalg::addRow(A, r1, r2, s1, s2)


linalg::addRow(A, r1, r2, s1) adds s1 times row r1 to row r2, in the matrix A.

linalg::addRow(A, r1, r2, s) returns a copy of the matrix A in which row r2 of A is replaced by srow(A, r1) + row(A, r2).

linalg::addRow(A, r1, r2, s1, s2) returns a copy of the matrix A in which row r2 of A is replaced by s1row(A, r1) + s2row(A, r2).


Example 1

The following defines a 3×3 matrix over the integers:

A := Dom::Matrix(Dom::Integer)( 
  [[1, 2, 3], [4, 5, 6], [7, 8, 9]] 

We replace the 2nd row by - row(A, 1) + row(A, 2), i.e., we subtract the first row from the second:

linalg::addRow(A, 1, 2, -1)

Example 2

The following defines a 2×3 matrix over the reals:

B := Dom::Matrix(Dom::Real)( 
  [[sin(2), 0, 1], [1, PI, 0]] 

If s is an expression that does not represent a real number then an error message is reported. The following tries to replace the 1st row by xrow(B, 2) + row(B, 1), where x is an identifier which cannot be converted to the component ring Dom::Real of B:

delete x: linalg::addRow(B, 2, 1, x)
Error: Unable to convert 'x'. [linalg::addRow]

Example 3

If symbolic expressions are involved, then one may define matrices over the component ring created by Dom::ExpressionField. The following example defines a matrix over this default component ring:

delete a11, a12, a21, a22, x:
C := matrix([[a11, a12], [a21, a22]])

We retry the input from the previous example:

linalg::addRow(C, 2, 1, x)



An m×n matrix of a domain of category Cat::Matrix

r1, r2

The row indices: positive integers less or equal to m

s, s1, s2

Expressions that can be converted to the component ring of A

Return Values

Matrix of the same domain type as A.

Was this topic helpful?