Repository: Qiskit/qiskit-terra (python)

Issue:
TensoredOp's to_matrix() returns a wrong value if coeff is not 1
### Environment

- **Qiskit Terra version**: 
  0.22.4
- **Python version**: 
  3.10.4
- **Operating system**: 
  Ubuntu 20.04.5 LTS


### What is happening?

`TensoredOp`'s `to_matrix()` returns a wrong value if coeff is not 1.

### How can we reproduce the issue?

Run the following code:
```
from qiskit.opflow import Plus, Zero
print((0.5 * (Plus ^ Zero)).to_matrix())
```

Then, the following will be printed:
```
[0.1767767+0.j 0.       +0.j 0.1767767+0.j 0.       +0.j]
```


### What should happen?

The following should be printed:
```
[0.35355339+0.j, 0.        +0.j, 0.35355339+0.j, 0.        +0.j]
```

### Any suggestions?

I think this problem is related to #9283.

Pull request:
Fix ``TensoredOp.to_matrix`` with global coefficients
<!--
⚠️ If you do not respect this template, your pull request will be closed.
⚠️ Your pull request title should be short detailed and understandable for all.
⚠️ Also, please add a release note file using reno if the change needs to be
  documented in the release notes.
⚠️ If your pull request fixes an open issue, please link to the issue.

- [ ] I have added the tests to cover my changes.
- [ ] I have updated the documentation accordingly.
- [ ] I have read the CONTRIBUTING document.
-->

### Summary

Fixes #9398.

### Details and comments

As the author of #9398 correctly pointed out, this is the analogous error fixed in #9283, where the global coefficient was multiplied with the matrix once per element in the tensored expression, when it should only be applied once.


Patch:
diff --git a/qiskit/opflow/list_ops/tensored_op.py b/qiskit/opflow/list_ops/tensored_op.py
index 3ff574f00..023c325d4 100644
--- a/qiskit/opflow/list_ops/tensored_op.py
+++ b/qiskit/opflow/list_ops/tensored_op.py
@@ -116,3 +116,9 @@ class TensoredOp(ListOp):
             "Conversion to_circuit supported only for operators, where a single "
             "underlying circuit can be produced."
         )
+
+    def to_matrix(self, massive: bool = False) -> np.ndarray:
+        OperatorBase._check_massive("to_matrix", True, self.num_qubits, massive)
+
+        mat = self.coeff * reduce(np.kron, [np.asarray(op.to_matrix()) for op in self.oplist])
+        return np.asarray(mat, dtype=complex)
diff --git a/releasenotes/notes/fix-tensoredop-to-matrix-6f22644f1bdb8b41.yaml b/releasenotes/notes/fix-tensoredop-to-matrix-6f22644f1bdb8b41.yaml
new file mode 100644
index 000000000..000dd81ee
--- /dev/null
+++ b/releasenotes/notes/fix-tensoredop-to-matrix-6f22644f1bdb8b41.yaml
@@ -0,0 +1,7 @@
+---
+fixes:
+  - |
+    Fixed a bug in :meth:`.TensoredOp.to_matrix` where the global coefficient of the operator
+    was multiplied to the final matrix more than once. Now, the global coefficient is correclty
+    applied, independent of the number of tensored operators or states.
+    Fixed `#9398 <https://github.com/Qiskit/qiskit-terra/issues/9398>`__.


Test patch:
diff --git a/test/python/opflow/test_op_construction.py b/test/python/opflow/test_op_construction.py
index 75a1b625c..d797c566b 100644
--- a/test/python/opflow/test_op_construction.py
+++ b/test/python/opflow/test_op_construction.py
@@ -1110,6 +1110,15 @@ class TestOpConstruction(QiskitOpflowTestCase):
 
         np.testing.assert_almost_equal(composed.to_matrix(), expected)
 
+    def test_tensored_op_to_matrix(self):
+        """Test tensored operators to matrix works correctly with a global coefficient.
+
+        Regression test of Qiskit/qiskit-terra#9398.
+        """
+        op = TensoredOp([X, I], coeff=0.5)
+        expected = 1 / 2 * np.kron(X.to_matrix(), I.to_matrix())
+        np.testing.assert_almost_equal(op.to_matrix(), expected)
+
 
 class TestOpMethods(QiskitOpflowTestCase):
     """Basic method tests."""
diff --git a/test/python/opflow/test_state_construction.py b/test/python/opflow/test_state_construction.py
index 909c284bd..6543fcbcf 100644
--- a/test/python/opflow/test_state_construction.py
+++ b/test/python/opflow/test_state_construction.py
@@ -236,6 +236,15 @@ class TestStateConstruction(QiskitOpflowTestCase):
         self.assertEqual(len(ex), 3)
         self.assertEqual(ex.eval(), 1)
 
+    def test_tensorstate_to_matrix(self):
+        """Test tensored states to matrix works correctly with a global coefficient.
+
+        Regression test of Qiskit/qiskit-terra#9398.
+        """
+        state = 0.5 * (Plus ^ Zero)
+        expected = 1 / (2 * np.sqrt(2)) * np.array([1, 0, 1, 0])
+        np.testing.assert_almost_equal(state.to_matrix(), expected)
+
 
 if __name__ == "__main__":
     unittest.main()