# Manipulate function not working possibly because of Arg?

I have the following function

eigen1 = 1/3*(p + sig - u2/(2^(8/3)*sig) - 3*I*ω);


Where

p = (Γ + κ1 + κ2)/2;
u1 = 36 g1^2 (-2 p + 3 κ2) + (36 g2^2 + (2 p - 3 κ1) (2 p - 3 κ2)) (4 p
- 3(κ1 + κ2));
u2 = (2^(2/3)*(12 g1^2 + 12 g2^2 - 4 p^2 + 6 p (κ1 + κ2) - 3 (κ1^2 + κ1 κ2 +
κ2^2)));
sig = ((u1 + Sqrt[u1^2 + u2^3])/16)^(1/3);


I am only interested in plotting the imaginary part of eigen1 as a function of g1 while varying the parameter g2 and letting the other parameters (κ1, κ2, Γ, ω) take on fixed values

testplot1 = ComplexExpand[Im[eigen1]] /. {Γ -> 1, κ1 -> 2, κ2 -> 3, ω -> 0};


This should leave testplot1 only dependent on g1 and g2. But doing

Manipulate[Plot[Evaluate@testplot1, {g1, 0, 5}, PlotRange -> All], {g2, 1, 10}]


returns a blank graph. I decided to print testplot1 to see if there are any missing variables that I have yet to define, but everything in testplot1 really is just a function of g1 and g2. Printing testplot1 gives

-((7 Sin[1/
3 Arg[108 g1^2 - 108 g2^2 +
Sqrt[(108 g1^2 - 108 g2^2)^2 +
4 (-3 + 12 g1^2 + 12 g2^2)^3]]])/(3 2^(
2/3) ((108 g1^2 -
108 g2^2 + (((108 g1^2 - 108 g2^2)^2 +
4 (-3 + 12 g1^2 + 12 g2^2)^3)^2)^(1/4)
Cos[1/2 Arg[(108 g1^2 - 108 g2^2)^2 +
4 (-3 + 12 g1^2 + 12 g2^2)^3]])^2 +
Sqrt[((108 g1^2 - 108 g2^2)^2 +
4 (-3 + 12 g1^2 + 12 g2^2)^3)^2]
Sin[1/2 Arg[(108 g1^2 - 108 g2^2)^2 +
4 (-3 + 12 g1^2 + 12 g2^2)^3]]^2)^(1/6))) + (2 2^(1/3)
Sin[1/3 Arg[
108 g1^2 - 108 g2^2 +
Sqrt[(108 g1^2 - 108 g2^2)^2 +
4 (-3 + 12 g1^2 + 12 g2^2)^3]]])/(3 ((108 g1^2 -
108 g2^2 + (((108 g1^2 - 108 g2^2)^2 +
4 (-3 + 12 g1^2 + 12 g2^2)^3)^2)^(1/4)
Cos[1/2 Arg[(108 g1^2 - 108 g2^2)^2 +
4 (-3 + 12 g1^2 + 12 g2^2)^3]])^2 +
Sqrt[((108 g1^2 - 108 g2^2)^2 + 4 (-3 + 12 g1^2 + 12 g2^2)^3)^2]
Sin[1/2 Arg[(108 g1^2 - 108 g2^2)^2 +
4 (-3 + 12 g1^2 + 12 g2^2)^3]]^2)^(1/6)) + (2 2^(1/3)
g1^2 Sin[
1/3 Arg[108 g1^2 - 108 g2^2 +
Sqrt[(108 g1^2 - 108 g2^2)^2 +
4 (-3 + 12 g1^2 + 12 g2^2)^3]]])/((108 g1^2 -
108 g2^2 + (((108 g1^2 - 108 g2^2)^2 +
4 (-3 + 12 g1^2 + 12 g2^2)^3)^2)^(1/4)
Cos[1/2 Arg[(108 g1^2 - 108 g2^2)^2 +
4 (-3 + 12 g1^2 + 12 g2^2)^3]])^2 +
Sqrt[((108 g1^2 - 108 g2^2)^2 + 4 (-3 + 12 g1^2 + 12 g2^2)^3)^2]
Sin[1/2 Arg[(108 g1^2 - 108 g2^2)^2 +
4 (-3 + 12 g1^2 + 12 g2^2)^3]]^2)^(1/6) + (2 2^(1/3)
g2^2 Sin[
1/3 Arg[108 g1^2 - 108 g2^2 +
Sqrt[(108 g1^2 - 108 g2^2)^2 +
4 (-3 + 12 g1^2 + 12 g2^2)^3]]])/((108 g1^2 -
108 g2^2 + (((108 g1^2 - 108 g2^2)^2 +
4 (-3 + 12 g1^2 + 12 g2^2)^3)^2)^(1/4)
Cos[1/2 Arg[(108 g1^2 - 108 g2^2)^2 +
4 (-3 + 12 g1^2 + 12 g2^2)^3]])^2 +
Sqrt[((108 g1^2 - 108 g2^2)^2 + 4 (-3 + 12 g1^2 + 12 g2^2)^3)^2]
Sin[1/2 Arg[(108 g1^2 - 108 g2^2)^2 +
4 (-3 + 12 g1^2 + 12 g2^2)^3]]^2)^(1/6) + (1/(6 2^(1/3)))((108 g1^2 -
108 g2^2 + (((108 g1^2 - 108 g2^2)^2 +
4 (-3 + 12 g1^2 + 12 g2^2)^3)^2)^(1/4)
Cos[1/2 Arg[(108 g1^2 - 108 g2^2)^2 +
4 (-3 + 12 g1^2 + 12 g2^2)^3]])^2 +
Sqrt[((108 g1^2 - 108 g2^2)^2 + 4 (-3 + 12 g1^2 + 12 g2^2)^3)^2]
Sin[1/2 Arg[(108 g1^2 - 108 g2^2)^2 +
4 (-3 + 12 g1^2 + 12 g2^2)^3]]^2)^(1/6)Sin[1/3 Arg[
108 g1^2 - 108 g2^2 +
Sqrt[(108 g1^2 - 108 g2^2)^2 + 4 (-3 + 12 g1^2 + 12 g2^2)^3]]]]]]


which seems long and nasty. The point is that the only variables in here are g1 and g2 so Manipulate should really work and I don't know what went wrong. My initial diagnosis would be that the Arg that appears in testplot1 throughout was interfering with Manipulate but I am not sure if that's the real issue. I intend to vary not just g2 but eventually all of the other parameters (κ1, κ2, Γ, ω) down the road but I cannot vary even one parameter at this point. Any thoughts?

• Manipulate is working fine for me, it plots a line that is 0 everywhere. Try dropping the ComplexExpand, which is really only a function for manipulating the form of an equation, and then re-print testplot you'll see that you're trying to take the imaginary part of a real number, which is why this is 0 regardless of the values of g1 and g2. It looks like there may be values of g1 and g2 for which this has an imaginary part, but it isn't imaginary in general. Sep 7, 2018 at 15:31
• If you use the Re part of eigen1 Manipulate does seem to give a blank plot, so your problem still stands, but I think you could reduce this to an MWE. My guess is it has to do with some tricky evaluation, since if I copy and paste the expression for Re[eigen1] /. {\[CapitalGamma] -> 1, \[Kappa]1 -> 2, \[Kappa]2 -> 3, \[Omega] -> 0} directly into the manipulate it works. Sep 7, 2018 at 15:40
• After dropping ComplexExpand, I concur that there may be values of g1 and g2 for which it becomes imaginary, since there is a square root in the denominator and it's possible to make the argument less than 0 by picking appropriate g1 and g2 values. But why wouldn't manipulate take that into account when I'm varying g1 and g2? Surely if I keep increasing g1 and g2 it should be imaginary but this is not the case even if I increase the range of g1 and g2 from 5 to 50 and 10 to 100 respectively Sep 7, 2018 at 15:46
• I've provided one solution to an MWE demonstrating the problem you're seeing. There might be a better answer addressing this problem already, evaluation in Manipulate can get hairy but there are some experts around. DynamicModule is a little more work, but can make things more straight forward, you might search the site for some old questions about Manipulate and DynamicModule. Sep 7, 2018 at 15:50

As I said in my comment, your plot will always give you 0, since you're trying to take the Im part of a real number - before you print test1 for examination you should get rid of the ComplexExpand, it will be easier to interpret. Here is an MWE of the issue with Manipulate

test=y*x;
Manipulate[
Plot[test,{x,0,1}],
{y,0,1}
]


This gives a blank plot, one solution is:

test=y*x;
Manipulate[
Plot[test/.y->yy,{x,0,1}],
{yy,0,1}
]


Though I doubt this is the canonical way to handle this sort of thing.

• After much fumbling with Manipulate, I do think that this is the best way to handle the function in my case. I would have never thought to redefined my variables inside Manipulate. I did Manipulate[ Plot[Evaluate@testplot1 /. {g2 -> gg}, {g1, 0, 5}, PlotRange -> All], {gg, 0, 15, 0.1}] and I got what I was looking for (reasonably). Thanks @N.J.Evans ! Sep 7, 2018 at 16:45