Hello, I have a complicated expression and I'd like to know where the global maximum locates. To find the global maximum numerically in a certain range, I used NMaximize in Mathematica, but, since my equation is too complicated and might generate complex numbers with some ranges of values, Mathematica stops running my script and returns error message whenever it meets complex numbers during computation (it assumes all the parameters are real numbers in NMaximize by default).
In order to exclude imaginary numbers, I constrained all the cube root and square root terms in my expression to be real. However, the computation was still stopped by complex numbers and returned error message.
I was wondering has anyone here come across the same problem or know what might be the reason?
Thanks for the help.
Below is my code:
NMaximize[{-(10.3024 b (-72. a1^3 b^2 B + 6.9282 Sqrt[a1^6 b^3 (2. (b - 2. ^3 + 108 b B^2)])^(1/3) N0 (-1. + PE) (a1^2 B^2 (-0.5 + 1. PE) + 0.109198 (-72. a1^3 B^3 PE + 6.9282 Sqrt[a1^6 B^6 (2. + PE (-12. + (132. - 16. PE) PE))])^(2/3)))/(B (a1^2 b (-4.57886 b + 9.15771 + 1. (-72. a1^3 b^2 B +6.9282 Sqrt[a1^6 b^3 (2. (b - 2. ^3 + 108 b B^2)])^(2/3)) (0.125 + 1. PE) (-72. a1^3 B^3 PE + 6.9282 Sqrt[a1^6 B^6 (2. + PE (-12. + (132. - 16. PE) PE))])^(1/3) \[Rho]2),
1 >= PE >= 0 && a1 > 0 && b > 0 && B > 0 && N0 > 0 && \[Rho]2 > 0 &&
Element[Sqrt[a1^6 b^3 (2. (b - 2. ^3 + 108 b B^2)], Reals] &&
Element[(-72. a1^3 b^2 B +6.9282 Sqrt[a1^6 b^3 (2. (b - 2. ^3 + 108 b B^2)])^(1/3), Reals] &&
Element[ (-72. a1^3 B^3 PE +6.9282 Sqrt[a1^6 B^6 (2. + PE (-12. + (132. - 16. PE) PE))])^(2/3), Reals] &&
Element[Sqrt[a1^6 B^6 (2. + PE (-12. + (132. - 16. PE) PE))],Reals] &&
Element[(-72. a1^3 b^2 B +6.9282 Sqrt[a1^6 b^3 (2. (b - 2. ^3 + 108 b B^2)])^(2/3),Reals] &&
Element[Sqrt[a1^6 b^3 (2. (b - 2. ^3 + 108 b B^2)], Reals] &&
Element[(-72. a1^3 B^3 PE +6.9282 Sqrt[a1^6 B^6 (2. + PE (-12. + (132. - 16. PE) PE))])^(1/3), Reals] &&
Element[Sqrt[a1^6 B^6 (2. + PE (-12. + (132. - 16. PE) PE))],Reals]}, {PE, a1, b, B, N0, \[Rho]2}]
And this is the error message it returned:
NMaximize::nrnum: The function value 1.10779 +1.35959 I is not a real number at {a1,b,B,N0,PE,\[Rho]2} = {1.94959,1.24058,1.25931,1.9308,0.306576,1.2403}. >>
Then I subsituded the set of values that error message provided back to constrained terms and found there are two cubic root terms that still generated imaginary numbers after they were constrained:
(-72. a1^3 b^2 B + 6.9282 Sqrt[a1^6 b^3 (2. (b - 2. B)^3 + 108 b B^2)])^(1/ 3) /.
{a1 -> 1.9495938054894624`, b -> 1.2405752948531126`,
B -> 1.2593144096464886`, N0 -> 1.9307969865057644`,
PE -> 0.30657581321875266`, \[Rho]2 -> 1.2403032542691323`}
>>1.08472 + 1.8788 I
(-72. a1^3 b^2 B + 6.9282 Sqrt[a1^6 b^3 (2. (b - 2. B)^3 + 108 b B^2)])^(2/3) /.
{a1 -> 1.9495938054894624`, b -> 1.2405752948531126`,
B -> 1.2593144096464886`, N0 -> 1.9307969865057644`,
PE -> 0.30657581321875266`, \[Rho]2 -> 1.2403032542691323`}
>>-2.35325 + 4.07595 I