
The blockdiag() Function in Scilab
Scilab's blockdiag() function is a powerful tool designed for constructing diagonal matrices.
blockdiag(x,y,z,...)
The parameters enclosed within the parentheses denote the values intended for the matrix's diagonal.
Executing this function yields a block matrix, with the specified values populating the diagonal and all other elements set to zero.
Interestingly, the function isn't limited to individual values. Arrays can also serve as arguments. When arrays are provided, the function seamlessly arranges them in blocks along the matrix's diagonal.
For clarity, consider the following example.
To create a square matrix with the values 1, 2, and 3 on the main diagonal, you'd use:
blockdiag(1,2,3)
This command produces:
ans =
1. 0. 0.
0. 2. 0.
0. 0. 3.
Let's delve a bit deeper. Create three arrays: A, B, and C.
A=[1,2];
B=[3,4,5];
C=[6,7];
Now, employ the blockdiag() function to generate a block diagonal matrix:
blockdiag(A,B,C)
The resulting matrix is
ans =
1. 2. 0. 0. 0. 0. 0.
0. 0. 3. 4. 5. 0. 0.
0. 0. 0. 0. 0. 6. 7.
Observe how the matrix prominently displays arrays A, B, and C on its main diagonal, while the remaining elements are zeros.