0
$\begingroup$

I am facing a problem in plotting the Piecewise function. I simplified my problem to take the following form:

enter image description here

where \[Sigma][i] are Pauli matrices. My code is:

\[Sigma][1] = PauliMatrix[1]; \[Sigma][2] = 
 PauliMatrix[2];    \[Sigma][3] = PauliMatrix[3];
DM = {{2 t, 0, 0, 8}, {0, 8, 10, 0}, {0, 15, 5, 0}, {2, 0, 0, 3}};
x[i_] = Tr[DM.(KroneckerProduct[\[Sigma][i], \[Sigma][i]])];
X = {{x[1], x[2], x[3]}};
{\[Lambda]1, \[Lambda]2, \[Lambda]3, \[Lambda]4} = Eigenvalues[DM];
MR = Piecewise[{{Tr[DM.DM\[Transpose]] - Norm[X], 
    X != 0}, {Max[\[Lambda]1, \[Lambda]2, \[Lambda]3, \[Lambda]4], 
    X = 0}}]
Plot[MR, {t, 0, 100}] 
$\endgroup$

1 Answer 1

4
$\begingroup$

In your piecewise definition, you're comparing a vector with a number (zero). This won't work:

{1, 1} == 0
(* {1, 1} == 0 *)

Instead, you need to compare to the zero vector:

{1, 1} == {0, 0}
(* False *)

Also, you had a typo in the piecewise, it should be X == {0, 0} instead of X = {0, 0}, although MMA 12.1 auto-corrected it. Here's the final code that produces a plot:

σ[1] = PauliMatrix[1]; 
σ[2] = PauliMatrix[2]; 
σ[3] = PauliMatrix[3];
DM = {{2 t, 0, 0, 8}, {0, 8, 10, 0}, {0, 15, 5, 0}, {2, 0, 0, 3}};
x[i_] = Tr[DM.(KroneckerProduct[σ[i], σ[i]])];
X = {{x[1], x[2], x[3]}};
{λ1, λ2, λ3, λ4} = Eigenvalues[DM];
MR = Piecewise[{{Tr[DM.DM\[Transpose]] - Norm[X], 
    X != {0, 0}}, 
    {Max[λ1, λ2, λ3, λ4], 
    X == {0, 0}}}]
Plot[MR, {t, 0, 100}]

Plot

$\endgroup$
1
  • $\begingroup$ Thank you very much, I got the right results. $\endgroup$
    – Bekaso
    Apr 11, 2020 at 12:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.