Main Content

getMatrix

Matrix representation of observable

Since R2024b

    Installation Required: This functionality requires MATLAB Support Package for Quantum Computing.

    Description

    H = getMatrix(o) returns the sparse Hermitian matrix representation of the specified observable. For more information, see Matrix Representation of Observable.

    example

    Examples

    collapse all

    Create an observable from a two-qubit Pauli basis measurement where the X measurement basis is observed on the first and second qubits with weight 2.4 and the Z measurement basis is observed on the first qubit with weight –1.2.

    o = observable(["XX" "ZI"],[2.4 -1.2]);

    Get the sparse Hermitian matrix representation of the observable.

    H = getMatrix(o)
    H = 4×4 sparse double matrix (8 nonzeros)
       (1,1)      -1.2000
       (4,1)       2.4000
       (2,2)      -1.2000
       (3,2)       2.4000
       (2,3)       2.4000
       (3,3)       1.2000
       (1,4)       2.4000
       (4,4)       1.2000
    
    

    Input Arguments

    collapse all

    Observable, specified as an observable object.

    Output Arguments

    collapse all

    Matrix representation of the observable, returned as a sparse Hermitian matrix. The size of the matrix is 2n-by-2n, where n is the number of qubits in the quantum circuit or state.

    Limitations

    • As the number of qubits n increases, the size of the matrix grows exponentially as 2n-by-2n. So, using getMatrix is practical only when n is less than about 15.

    More About

    collapse all

    Version History

    Introduced in R2024b