0
$\begingroup$

In my code, I want to plot (Dis[t]). The problem is some functions containing in the code do not work well if there are variables in the form of symbols, such as "Sort" "NMaximize" functions.

enter image description here

I want to be sure that \[Omega]a, \[Omega]b are the largest eigenvalues of \[CapitalLambda]u. So I would like to tell Mathematica not to do a run of the code except when all the elements of the matrix (Rho) are numerical. How can I do this?

\[Rho]Mat = {{\[Kappa]^4/(
     J^4 \[ScriptV]^4 (1 + \[Kappa]^2/(
        J^2 \[ScriptV]^2))^2) + \[Mu]^4/(
     J^4 \[ScriptV]^4 (1 + \[Mu]^2/(J^2 \[ScriptV]^2))^2) + (
     E^(-2 I t \[Sigma] - 
       2 t \[Gamma] \[Sigma]^2) \[Kappa]^2 \[Mu]^2)/(
     J^4 \[ScriptV]^4 (1 + \[Kappa]^2/(
        J^2 \[ScriptV]^2)) (1 + \[Mu]^2/(J^2 \[ScriptV]^2))) + (
     E^(2 I t \[Sigma] - 
       2 t \[Gamma] \[Sigma]^2) \[Kappa]^2 \[Mu]^2)/(
     J^4 \[ScriptV]^4 (1 + \[Kappa]^2/(
        J^2 \[ScriptV]^2)) (1 + \[Mu]^2/(J^2 \[ScriptV]^2))), 0, 0, 
    SuperStar[(\[Kappa]^3/(
      J^3 \[ScriptV]^3 (1 + \[Kappa]^2/(
         J^2 \[ScriptV]^2))^2) + \[Mu]^3/(
      J^3 \[ScriptV]^3 (1 + \[Mu]^2/(J^2 \[ScriptV]^2))^2) + (
      E^(2 I t \[Sigma] - 2 t \[Gamma] \[Sigma]^2) \[Kappa]^2 \[Mu])/(
      J^3 \[ScriptV]^3 (1 + \[Kappa]^2/(
         J^2 \[ScriptV]^2)) (1 + \[Mu]^2/(J^2 \[ScriptV]^2))) + (
      E^(-2 I t \[Sigma] - 
        2 t \[Gamma] \[Sigma]^2) \[Kappa] \[Mu]^2)/(
      J^3 \[ScriptV]^3 (1 + \[Kappa]^2/(
         J^2 \[ScriptV]^2)) (1 + \[Mu]^2/(J^2 \[ScriptV]^2))))]}, {0, 
    0, 0, 0}, {0, 0, 0, 
    0}, {\[Kappa]^3/(
     J^3 \[ScriptV]^3 (1 + \[Kappa]^2/(
        J^2 \[ScriptV]^2))^2) + \[Mu]^3/(
     J^3 \[ScriptV]^3 (1 + \[Mu]^2/(J^2 \[ScriptV]^2))^2) + (
     E^(2 I t \[Sigma] - 2 t \[Gamma] \[Sigma]^2) \[Kappa]^2 \[Mu])/(
     J^3 \[ScriptV]^3 (1 + \[Kappa]^2/(
        J^2 \[ScriptV]^2)) (1 + \[Mu]^2/(J^2 \[ScriptV]^2))) + (
     E^(-2 I t \[Sigma] - 2 t \[Gamma] \[Sigma]^2) \[Kappa] \[Mu]^2)/(
     J^3 \[ScriptV]^3 (1 + \[Kappa]^2/(
        J^2 \[ScriptV]^2)) (1 + \[Mu]^2/(J^2 \[ScriptV]^2))), 0, 
    0, \[Kappa]^2/(
     J^2 \[ScriptV]^2 (1 + \[Kappa]^2/(
        J^2 \[ScriptV]^2))^2) + \[Mu]^2/(
     J^2 \[ScriptV]^2 (1 + \[Mu]^2/(J^2 \[ScriptV]^2))^2) + (
     E^(-2 I t \[Sigma] - 2 t \[Gamma] \[Sigma]^2) \[Kappa] \[Mu])/(
     J^2 \[ScriptV]^2 (1 + \[Kappa]^2/(
        J^2 \[ScriptV]^2)) (1 + \[Mu]^2/(J^2 \[ScriptV]^2))) + (
     E^(2 I t \[Sigma] - 2 t \[Gamma] \[Sigma]^2) \[Kappa] \[Mu])/(
     J^2 \[ScriptV]^2 (1 + \[Kappa]^2/(
        J^2 \[ScriptV]^2)) (1 + \[Mu]^2/(J^2 \[ScriptV]^2)))}};

\[Sigma]0 = {\[Sigma]x, \[Sigma]y, \[Sigma]z};
u = {Sin[\[Theta]] Cos[\[Phi]], Sin[\[Theta]] Sin[\[Phi]], 
   Cos[\[Theta]]};
u\[Sigma] = u.\[Sigma]0;
\[Chi] = KroneckerProduct[u\[Sigma], \[Sigma]I];
\[CapitalLambda]u = Sqrt[\[Rho]Mat].\[Chi].Sqrt[\[Rho]Mat];
ev = Eigenvalues[\[CapitalLambda]u];
 {\[Omega]a, \[Omega]b} = Sort[ev, Greater][[{1, 2}]];
 ff[t_, \[Theta]_, \[Phi]_] = {1 - Abs[Tr[\[CapitalLambda]u]] + 
     2 (\[Omega]a + \[Omega]b), 
    0 <= \[Theta] <= ( \[Pi]) && 0 <= \[Phi] <= (2 \[Pi])}  // 
   Simplify;
nmax[t_?NumericQ] := 
  NMaximize[ff[t, \[Theta], \[Phi]], {\[Theta], \[Phi]}];
Dis[t_] := Sqrt[(2 + Sqrt[2]) (1 - Sqrt[1/2*First@nmax[t]])];

Plot[Dis[t], {t, 0, 100}]
$\endgroup$
  • 1
    $\begingroup$ How about checking to see if the input is numeric? For example, define the function as Dist[t_?NumericQ] := $\endgroup$ – bill s Apr 19 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.