Hi, I have a conceptual doubt and don’t know where to ask so i tried to ask my doubt here.

The above is the quantum circuit and my doubt is how the matrix multiplication would be done after the Ry of second qubit , I mean to say that we know that CNOT is 4x4 matrix and if i start from the
[ 1 0 ] matrix of the second qubit and then evaluate the hadarmard gate matrix and then Ry matrix .So finally before the CNOT gate matrix for second qubit I will get the 1x2 matrix after the multiplication of Ry matrix in second qubit then the question is how should i proceed further to understand the matrix multiplicaion with CNOT gate matrix.

Can anybody please help me to understand mathematically how the final matrix for second qubit comes?
I want to know the final matrix of each qubit 1 and qubit 2.
Please help me to understand it

What you’re observing here is exactly the phenomenon of entanglement. When we only apply local gates to each qubit, we can represent each qubit’s state with just a 2-dimensional vector. However, as soon as we use a non-local gate (like the CNOT), this picture no longer works!

Instead, we have to consider the joint system (q[0], q[1]), which is represented by a 4-dimensional vector (one dimension for each possible computational basis state of the joint system (00, 01, 10, 11) ). Then multiplying by a CNOT (which is represented by a 4x4 matrix) makes sense.

This is exactly the phenomenon of entanglement. We can no longer describe the joint system using the individual subsystems.

What is the meaning of the above line?
what I understand is that the pauliZ gate is applied at the final i.e after CNOT gate to the second qubit and then calculating the expectation value of the second qubit.

My question is that now if they are in entangled state then how expectation value of individual qubit can be calculated like here the expectation value of second qubit is calculating?

in PennyLane translates to computing \langle \psi(\boldsymbol{\theta})\mid I\otimes Z\mid\psi(\boldsymbol \theta)\rangle. That is, we are computing the expectation value of the two qubit observable I_0\otimes Z_1 on the output state.

In PennyLane, the identity on the first qubit does not need to be explicitly provided — it is implicitly assumed if not present.

what I understand is that the pauliZ gate is applied at the final

Not quite — we are measuring the expectation value of the Pauli-Z observable, not applying a final Pauli-Z gate. To measure the expectation value of an observable experimentally, we perform the following process:

Evolve the circuit to the final state.

Apply additional gates to rotate the measured qubits into the measurement basis, if required. In the case of measuring in the Pauli-Z, no rotations are needed, so no additional gates are applied.

Sample from the measured qubits, and take the mean value.

if they are in entangled state then how expectation value of individual qubit can be calculated like here the expectation value of second qubit is calculating?

You can think of this in two ways — the approach above (taking the expectation value of I\otimes Z) or by tracing out the first subsystem to determine the reduced density matrix of the second subsystem. We can then take the expectation value of Z with respect to the reduced density matrix: