Edit
When I change the x range (e.g. {x,1,3}) I get the same error also for the direct expression. Thus, the problem exists either way and I assume it just evaluated different points?
Problem
I want to create a region plot of the following expression over lambda and x. When I use the expression as an argument it works great, but when I save the expression in a function, I get errors:
RegionPlot[ Log[Re[Cos[1/2 \[Pi] x Sqrt[1 - \[Lambda]]] Cos[ 1/2 \[Pi] x Sqrt[1 + \[Lambda]]] - ( Sin[1/2 \[Pi] x Sqrt[1 - \[Lambda]]] Sin[ 1/2 \[Pi] x Sqrt[1 + \[Lambda]]])/Sqrt[1 - \[Lambda]^2] + 1/2 \[Sqrt](1/(-1 + \[Lambda]^2) (2 - 3 \[Lambda]^2 + \[Lambda]^2 Cos[\[Pi] x Sqrt[ 1 + \[Lambda]]] + Cos[\[Pi] x Sqrt[ 1 - \[Lambda]]] (\[Lambda]^2 + (-2 + \[Lambda]^2) Cos[\ \[Pi] x Sqrt[1 + \[Lambda]]]) + 2 Sqrt[1 - \[Lambda]^2] Sin[\[Pi] x Sqrt[1 - \[Lambda]]] Sin[\[Pi] x Sqrt[ 1 + \[Lambda]]]))]] < 0, {\[Lambda], 0, 0.8}, {x, 0, 17.5}] This worked, but the following gives me errors.
staba[\[Lambda]_, x_] := Log[Re[Cos[1/2 \[Pi] x Sqrt[1 - \[Lambda]]] Cos[ 1/2 \[Pi] x Sqrt[1 + \[Lambda]]] - ( Sin[1/2 \[Pi] x Sqrt[1 - \[Lambda]]] Sin[ 1/2 \[Pi] x Sqrt[1 + \[Lambda]]])/Sqrt[1 - \[Lambda]^2] + 1/2 \[Sqrt](1/(-1 + \[Lambda]^2) (2 - 3 \[Lambda]^2 + \[Lambda]^2 Cos[\[Pi] x Sqrt[ 1 + \[Lambda]]] + Cos[\[Pi] x Sqrt[ 1 - \[Lambda]]] (\[Lambda]^2 + (-2 + \[Lambda]^2) Cos[\ \[Pi] x Sqrt[1 + \[Lambda]]]) + 2 Sqrt[1 - \[Lambda]^2] Sin[\[Pi] x Sqrt[1 - \[Lambda]]] Sin[\[Pi] x Sqrt[ 1 + \[Lambda]]]))]] RegionPlot[staba[\[Lambda], x] < 0, {\[Lambda], 0, 0.8}, {x, 0, 17.5}] It still gives me the same plot, but I get the errors
Less::nord: Invalid comparison with -1.01093+3.14159 I attempted. Less::nord: Invalid comparison with -1.00272+3.14159 I attempted. Less::nord: Invalid comparison with -1.01196+3.14159 I attempted. General::stop: Further output of Less::nord will be suppressed during this calculation. Solution Attempt
It seems like it uses pi once as an analytical constant and once as a number. This would result in Euler's identity not being evaluated in the second attempt. I tried with Evaluate or changing the delayed evaluation (":=" vs. "="). But this did not help. I also get the same problem using the max function instead of the region plot (see below). I could not find anything online, so I'd be glad for explanations and solutions.
Similar Problem & Context
The code is to reproduce Fig. 1.6 from Classical and Quantum Parametric Phenomena. The full code is:
$Assumptions = x \[Element] Reals; w[t_, \[Lambda]_, \[Omega]0_] := {{Cos[\[Omega]0 Sqrt[ 1 - \[Lambda]] t], Sin[\[Omega]0 Sqrt[1 - \[Lambda]] t]}, {-\[Omega]0 Sqrt[ 1 - \[Lambda]] Sin[\[Omega]0 Sqrt[ 1 - \[Lambda]] t], \[Omega]0 Sqrt[ 1 - \[Lambda]] Cos[\[Omega]0 Sqrt[1 - \[Lambda]] t]}}; w[t_, \[Lambda]_] = ( { {Cos[\[Omega]0 Sqrt[1 - \[Lambda]] t], Sin[\[Omega]0 Sqrt[1 - \[Lambda]] t]}, {-\[Omega]0 Sqrt[1 - \[Lambda]] Sin[\[Omega]0 Sqrt[1 - \[Lambda]] t], \[Omega]0 Sqrt[ 1 - \[Lambda]] Cos[\[Omega]0 Sqrt[1 - \[Lambda]] t]} } ); \[CapitalPhi][Tp, 0][\[Lambda]_] = w[Tp, -\[Lambda]] . Inverse[w[Tp/2, -\[Lambda]]] . w[Tp/2, \[Lambda]] . Inverse[w[0, \[Lambda]]]; ca[\[Lambda]_] = Tr[\[CapitalPhi][Tp, 0][\[Lambda]]]/2 + Sqrt[(Tr[\[CapitalPhi][Tp, 0][\[Lambda]]]/2)^2 - 1]; cb[\[Lambda]_] = Tr[\[CapitalPhi][Tp, 0][\[Lambda]]]/2 - Sqrt[(Tr[\[CapitalPhi][Tp, 0][\[Lambda]]]/2)^2 - 1]; \[Mu]a[\[Lambda]_, \[CapitalGamma]_] = Log[Re[ca[\[Lambda]]]]/Tp - \[CapitalGamma]/2; \[Mu]b[\[Lambda]_, \[CapitalGamma]_] = Log[Re[cb[\[Lambda]]]]/Tp - \[CapitalGamma]/2; stability[\[Lambda]_, \[CapitalGamma]_, x_] = Max[Tp \[Mu]a[\[Lambda], \[CapitalGamma]] /. {Tp -> ( x \[Pi])/\[Omega]0}, Tp \[Mu]b[\[Lambda], \[CapitalGamma]] /. {Tp -> ( x \[Pi])/\[Omega]0}]; RegionPlot[ stability[\[Lambda], 0, x] > 0, {\[Lambda], 0, 0.8}, {x, 0, 17.5}, PlotPoints -> 10] (* PC too slow *) Here I get the errors again also for the max function
Max::nord: Invalid comparison with -0.458641+3.14159 I attempted. Max::nord: Invalid comparison with 0.458641 +3.14159 I attempted. Greater::nord2: Comparison of Max[-0.458641+3.14159 I,0.458641 +3.14159 I] and 0 is invalid. Max::nord: Invalid comparison with -0.542381+3.14159 I attempted. General::stop: Further output of Max::nord will be suppressed during this calculation. Greater::nord2: Comparison of Max[-0.542381+3.14159 I,0.542381 +3.14159 I] and 0 is invalid. Greater::nord: Invalid comparison with -0.15055+3.14159 I attempted. Greater::nord2: Comparison of Max[-0.624644+3.14159 I,0.624644 +3.14159 I] and 0 is invalid. General::stop: Further output of Greater::nord2 will be suppressed during this calculation. Greater::nord: Invalid comparison with -0.286704+3.14159 I attempted. Greater::nord: Invalid comparison with -0.527562+3.14159 I attempted. General::stop: Further output of Greater::nord will be suppressed during this calculation. If I use the expression directly it doesn't produce any errors again.
RegionPlot, it can analyze it and determine its domain. When you give it as an external function, it will only numerically plug in the values, hence it will encounter an error at some points. (3) This issue is commonly solved by eitherRegionPlot[Evaluate[staba[λ, x] < 0], {λ, 0, 0.8}, {x, 0, 17.5}]orRegionPlot[staba[λ, x] < 0, {λ, 0, 0.8}, {x, 0, 17.5}, Evaluated -> True]. $\endgroup$norderrors come from a negative argument toLogthat is not internallyQuiet-ed. TryOn[Log]; staba[0.5, 1.]; Off[Log]orOn[Log]; stability[0.5, 0, 1.]; Off[Log]. (And$Assumptionsaffects only functions that use it, and there are none such in your codes.) In the last code,\[Omega]0is undefined instability. $\endgroup$