Main Content

pagepinv

Page-wise Moore-Penrose pseudoinverse

Since R2024a

    Description

    B = pagepinv(A) computes the Moore-Penrose pseudoinverse of each page of N-D array A. Each page of the output array B is given by B(:,:,i) = pinv(A(:,:,i)).

    If A has more than three dimensions, then pagepinv returns an N-D array with the same dimensions, as in B(:,:,i,j,k) = pinv(A(:,:,i,j,k)).

    example

    B = pagepinv(A,tol) specifies a value for one or more tolerances. pagepinv treats singular values of the pages of A that are less than or equal to the corresponding tolerance as zero.

    example

    Examples

    collapse all

    Create a 3-by-3-by-3 array.

    A = cat(3,magic(3),hilb(3),pascal(3))
    A = 
    A(:,:,1) =
    
         8     1     6
         3     5     7
         4     9     2
    
    
    A(:,:,2) =
    
        1.0000    0.5000    0.3333
        0.5000    0.3333    0.2500
        0.3333    0.2500    0.2000
    
    
    A(:,:,3) =
    
         1     1     1
         1     2     3
         1     3     6
    
    

    Calculate the matrix pseudoinverse of each array page.

    B = pagepinv(A)
    B = 
    B(:,:,1) =
    
        0.1472   -0.1444    0.0639
       -0.0611    0.0222    0.1056
       -0.0194    0.1889   -0.1028
    
    
    B(:,:,2) =
    
        9.0000  -36.0000   30.0000
      -36.0000  192.0000 -180.0000
       30.0000 -180.0000  180.0000
    
    
    B(:,:,3) =
    
        3.0000   -3.0000    1.0000
       -3.0000    5.0000   -2.0000
        1.0000   -2.0000    1.0000
    
    

    Create a 3-by-3-by-3 array.

    A = cat(3,magic(3),hilb(3),pascal(3))
    A = 
    A(:,:,1) =
    
         8     1     6
         3     5     7
         4     9     2
    
    
    A(:,:,2) =
    
        1.0000    0.5000    0.3333
        0.5000    0.3333    0.2500
        0.3333    0.2500    0.2000
    
    
    A(:,:,3) =
    
         1     1     1
         1     2     3
         1     3     6
    
    

    Create a 1-by-1-by-3 array of tolerances.

    tol = cat(3,2,0.2,1)
    tol = 
    tol(:,:,1) =
    
         2
    
    
    tol(:,:,2) =
    
        0.2000
    
    
    tol(:,:,3) =
    
         1
    
    

    Calculate the matrix pseudoinverse of each page with the corresponding tolerance value.

    B = pagepinv(A,tol)
    B = 
    B(:,:,1) =
    
        0.1472   -0.1444    0.0639
       -0.0611    0.0222    0.1056
       -0.0194    0.1889   -0.1028
    
    
    B(:,:,2) =
    
        0.4857    0.2701    0.1899
        0.2701    0.1502    0.1056
        0.1899    0.1056    0.0742
    
    
    B(:,:,3) =
    
        0.0048    0.0116    0.0212
        0.0116    0.0283    0.0516
        0.0212    0.0516    0.0939
    
    

    Input Arguments

    collapse all

    Input array, specified as a matrix or multidimensional array.

    Data Types: single | double
    Complex Number Support: Yes

    Singular value tolerance, specified as a scalar or a multidimensional array of size [1 1 size(A, 3:ndims(A))]. Specify a scalar tolerance to use the same tolerance for all array pages. Specify an array of tolerances to use a different tolerance for each page. pagepinv treats singular values that are less than or equal to tol as zeros during the computation of the pseudoinverse.

    The default tolerance is max(size(A, [1 2])) * eps(pagenorm(A)).

    Example: pagepinv(A,1e-4)

    More About

    collapse all

    Array Pages

    Page-wise functions like pagepinv operate on 2-D matrices that have been arranged into a multidimensional array. For example, the elements in the third dimension of a 3-D array are commonly called pages because they stack on top of each other like pages in a book. Each page is a matrix that the function operates on.

    3-D array with several matrices stacked on top of each other as pages in the third dimension

    You can also assemble a collection of 2-D matrices into a higher dimensional array, like a 4-D or 5-D array, and in these cases pagepinv still treats the fundamental unit of the array as a 2-D matrix that the function operates on, such as X(:,:,i,j,k,l).

    The cat function is useful for assembling a collection of matrices into a multidimensional array, and the zeros function is useful for preallocating a multidimensional array.

    Tips

    • Results obtained using pagepinv are numerically equivalent to computing the pseudoinverses of each of the same matrices in a for-loop. However, the two results might differ slightly due to floating-point round-off error.

    Extended Capabilities

    Version History

    Introduced in R2024a