Maple code for matrix

104 Views Asked by At

For the $n\times n$ matrix $M:=[m_{ij}]_{i,j=1}^{n}$, we have $$ m_{‎ii‎}=\sum_{j=1, j‎\neq i‎}^{‎n‎}‎m_{‎ij‎‎}‎,\ \ \ \ \ ‎i=1,...,‎n,‎‎ $$ I want to write Maple code for this matrix such that all off-diagonal entries $m_{‎ij‎‎}, \ i\neq j‎ ‎$ are known. In fact, how I can write maple code for generate all diagonal entries?

1

There are 1 best solutions below

0
On

One can modify the entries of a matrix using the assignment operator :=.

So, if $(m_{ij})$, $i \neq j$, are given as a matrix m with off-diagonal entries $m_{ij}$ (and arbitrary diagonal entries), we can recover $M$ with the following procedure:

d := proc(m) local n, i;
    n := LinearAlgebra:-Dimension(m)[1];
    for i from 1 to n do
        m[i, i] := add(m[i, j], j=1..n) - m[i, i]
    od;
    return m
end proc;

NB this procedure actually modifies the argument $m$.