Converts a vector of appropriate length to a square matrix form and vice versa.
y = sqrform(x)
A vector of appropriate length or a square matrix.
A square matrix or a vector depending on whether the input is a vector or a square matrix.
It converts a vector of appropriate length to a square matrix or a square square matrix to a 1-d or 2d array. If the input is a vector of length 3,6,10,15,21 etc then a symmmetric square matrix is formed. If a symmetrix square matrix is given as input, the lower diagonal elements are returned in a vector. If the square matrix given as input is not symmetrix, the elements of the upper and lower trinagular matrices are retruned as a 2-d array.
x=[1 2 3 4 5 6 7 8 9 10]; // Converting a vector to a square form y=sqrform(x) // Extracting upper trigular matrix from a square matrix y1=sqrform(y) // Magic square of size 8x8 x=testmatrix('magic',8); // Extracting upper and lower trinagular matrices of the magic square y2=sqrform(x) | ![]() | ![]() |