# Using MaxValue with complex argument

I know MaxValue is supposed to work with real numbers only, but there is some situations where a real valued function has complex terms anyway. Even with these complex terms, the function is still real valued. For example, consider the function $f:\mathbb{C}\to\mathbb{R}$ such that $f(z)=|z|$. It's not hard to come up with a lot more examples.

I wonder whether exist a way to maximize functions like this using Mathematica. In this example in particular, I have the following code

s = Abs[a + I*b]^2;
MaxValue[{s, a^2 + b^2 <= 1}, {a, b}, Reals]


which Mathematica replies with MaxValue::objc: The objective function Abs[a+I b]^2 contains a nonreal constant I. >>.

When $a,b\in\mathbb{R}$ is clear that $|a+ib|^2$ is also real. In fact, the absolute value of any complex value is real, so why Mathematica is complaining about the imaginary number $i$ ? I know Mathematica is able to come up some simplification for this expression! Even without simlpification, Mathematica should know that the absolute value only outputs real values.

PS: the question is not about the example I gave, but about maximizing complex expressions (functions) which will be real after some simplification.

Thank you!

Since s is real-valued you can probably convert it into an explicit real form using ComplexExpand. In some cases you may need to use the ComplexExpand option TargetFunctions to get an appropriate form. For example,

s = Abs[a + I*b]^2 // ComplexExpand

(*  a^2 + b^2  *)

MaxValue[{s, a^2 + b^2 <= 1}, {a, b}]

(*  1  *)

• For some reason, this is not working here. The command s = Abs[a + I*b]^2 // ComplexExpand still gives Abs[a + I b]^2 as output (and using MaxValue after gives the same problem). – Integral Oct 21 '16 at 13:21
• @Integral - What Mathematica version and OS are you using? I am using v11.0.1 on macOS Sierra 10.12 – Bob Hanlon Oct 21 '16 at 13:25
• I'm using version 9. But nevermind, I just realized that TargetFunction->{Re,Im} solves the problem! – Integral Oct 21 '16 at 13:28