# crzGate

Controlled z-axis rotation gate

Since R2023a

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

## Syntax

``g = crzGate(controlQubit,targetQubit,theta)``

## Description

example

````g = crzGate(controlQubit,targetQubit,theta)` applies a controlled z-axis rotation gate to a target qubit based on the state of a control qubit and returns a `quantum.gate.SimpleGate` object. If the control qubit is in the $|0〉$ state, then this gate does nothing. If the control qubit is in the $|1〉$ state, then this gate rotates the target qubit state around the z-axis by an angle of `theta`. If `controlQubit`, `targetQubit`, and `theta` are vectors of the same length, `crzGate` returns a column vector of gates, where `g(i)` represents a controlled z-axis rotation gate applied to the `i`th element triplet of `controlQubit`, `targetQubit`, and `theta`. If any of `controlQubit`, `targetQubit`, or `theta` is a scalar, and at least one of the inputs is a vector, then MATLAB® expands the scalar to match the size of the vector input.The qubit indices in each element pair of `controlQubit` and `targetQubit` must not be the same.```

## Examples

collapse all

Create a controlled z-axis rotation gate that acts on a control qubit with index 1 and a target qubit with index 2 using a rotation angle of `pi/2`.

`g = crzGate(1,2,pi/2)`
```g = SimpleGate with properties: Type: "crz" ControlQubits: 1 TargetQubits: 2 Angles: 1.5708```

Get the matrix representation of the gate.

`M = getMatrix(g)`
```M = 1.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 1.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.7071 - 0.7071i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.7071 + 0.7071i```

Create an array of three controlled z-axis rotation gates. The first gate acts on control qubit 1 and target qubit 2 with rotation angle `pi/4`, the next gate acts on control qubit 2 and target qubit 3 with rotation angle `pi/2`, and the final gate acts on control qubit 3 and target qubit 4 with rotation angle `3*pi/4`.

`g = crzGate(1:3,2:4,pi/4*(1:3))`
```g = 3×1 SimpleGate array with gates: Id Gate Control Target Angle 1 crz 1 2 pi/4 2 crz 2 3 pi/2 3 crz 3 4 3pi/4```

## Input Arguments

collapse all

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

Example: `2`

Example: `6:8`

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

Example: `1`

Example: `3:5`

Rotation angle, specified as a real scalar or vector.

Example: `pi`

Example: `(1:3)*pi/2`

collapse all

### Matrix Representation of Controlled z-Axis Rotation Gate

The matrix representation of a controlled z-axis rotation gate applied to control qubit 1 and target qubit 2 with a rotation angle of $\theta$ is

`$\left[\begin{array}{cccc}1& 0& 0& 0\\ 0& 1& 0& 0\\ 0& 0& \mathrm{exp}\left(-i\text{\hspace{0.17em}}\frac{\theta }{2}\right)& 0\\ 0& 0& 0& \mathrm{exp}\left(i\text{\hspace{0.17em}}\frac{\theta }{2}\right)\end{array}\right].$`

## Version History

Introduced in R2023a