expval
Method of Operator.
Overloads
| Name | Description |
|---|---|
expval(const State rhs) -> complex | Computes the expectation value of an Operator for a given state. Calculates <|O|>, where is a quantum state and is an operator. |
expval(const RealMatrix rhs) -> real | Computes the expectation value of an Operator in a given real state. Calculates <|O|>, where is a state vector and is an operator. |
expval(const ComplexMatrix rhs) -> complex | Computes the expectation value of an Operator in a given complex state. Calculates <|O|>. |
expval(const State rhs) -> complex
Computes the expectation value of an Operator for a given state. Calculates <|O|>, where is a quantum state and is an operator.
Parameters
- rhs: The state () in which the expectation value is computed.
Returns
The (complex) expectation value of the operator in the state.
Example
var state = Qbit("000101")
var value = expval(X(0), state) // Compute <state|X(0)|state>
expval(const RealMatrix rhs) -> real
Computes the expectation value of an Operator in a given real state. Calculates <|O|>, where is a state vector and is an operator.
Parameters
- rhs: The real state vector () in which the expectation value is computed.
Returns
The real expectation value of the operator in the state.
Example
var state = vector([4], as_real) // Create a real state vector, $\psi$
var value = expval(X(0), state) // Compute <state|X(0)|state>
expval(const ComplexMatrix rhs) -> complex
Computes the expectation value of an Operator in a given complex state. Calculates <|O|>.
Parameters
- rhs: The complex state vector in which the expectation value is computed.
Returns
The complex expectation value of the operator in the state.
Example
var state = vector([4]) // Create a complex state vector
var value = expval(X(0), state) // Compute <state|X(0)|state>