Main Content

hGate

Hadamard gate

Since R2023a

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

Description

example

g = hGate(targetQubit) applies a Hadamard gate to a single target qubit and returns a quantum.gate.SimpleGate object.

If targetQubit is a vector of qubit indices, hGate returns a column vector of gates, where g(i) represents a Hadamard gate applied to a qubit with index targetQubit(i).

Examples

collapse all

Create a Hadamard gate that acts on a single qubit.

g = hGate(1)
g = 

  SimpleGate with properties:

             Type: "h"
    ControlQubits: [1×0 double]
     TargetQubits: 1
           Angles: [1×0 double]

Get the matrix representation of the gate.

M = getMatrix(g)
M =

    0.7071    0.7071
    0.7071   -0.7071

Create an array of Hadamard gates that act on qubits with indices 1 to 4.

g = hGate(1:4)
g = 

  4×1 SimpleGate array with gates:

    Id   Gate   Control   Target
     1   h                1     
     2   h                2     
     3   h                3     
     4   h                4     

Input Arguments

collapse all

Target qubit of the gate, specified as a positive integer scalar index or vector of qubit indices.

Example: 1

Example: 3:5

More About

collapse all

Matrix Representation of Hadamard Gate

The matrix representation of a Hadamard gate applied to a single qubit is

12[1111].

This gate maps the qubit basis states from the Z basis to the X basis (and from the X basis to the Z basis), where the |0 and |1 states are mapped to the |+=|0+|12 and |=|0|12 states, respectively.

Version History

Introduced in R2023a