# cyGate

Controlled Y gate

Since R2023a

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

## Syntax

``g = cyGate(controlQubit,targetQubit)``

## Description

example

````g = cyGate(controlQubit,targetQubit)` applies a controlled Y 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 applies a Pauli Y gate (`yGate`) to the target qubit. If `controlQubit` and `targetQubit` are vectors of the same length, `cyGate` returns a column vector of gates, where `g(i)` represents a controlled Y gate applied to a control qubit with index `controlQubit(i)` and a target qubit with index `targetQubit(i)`. If either `controlQubit` or `targetQubit` is a scalar, and the other input 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 Y gate that acts on a control qubit with index 1 and a target qubit with index 2.

`g = cyGate(1,2)`
```g = SimpleGate with properties: Type: "cy" ControlQubits: 1 TargetQubits: 2 Angles: [1×0 double]```

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.0000 + 0.0000i 0.0000 - 1.0000i 0.0000 + 0.0000i 0.0000 + 0.0000i 0.0000 + 1.0000i 0.0000 + 0.0000i```

Create an array of three controlled Y gates. The first gate acts on control qubit 1 and target qubit 2, the next gate acts on control qubit 2 and target qubit 3, and the final gate acts on control qubit 3 and target qubit 4.

`g = cyGate(1:3,2:4)`
```g = 3×1 SimpleGate array with gates: Id Gate Control Target 1 cy 1 2 2 cy 2 3 3 cy 3 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`

collapse all

### Matrix Representation of Controlled Y Gate

The matrix representation of a controlled Y gate applied to control qubit 1 and target qubit 2 is

`$\left[\begin{array}{cccc}1& 0& 0& 0\\ 0& 1& 0& 0\\ 0& 0& 0& -i\\ 0& 0& i& 0\end{array}\right].$`

If the control qubit is in the $|0〉$ state, then this gate leaves the target qubit as is. If the control qubit is in the $|1〉$ state, then this gate applies a Pauli Y gate to the target qubit.

## Version History

Introduced in R2023a