0
$\begingroup$

I am having trouble with maximizing a function I am interested in. Below is the code I am using.

NMaximize[{(p^2)^alpha + ((c - p)^2)^alpha + (1 - (c - p)^2 - p^2)^alpha, 
  {c/2 - Sqrt[2 - c^2]/2 < p, p < c/2 + Sqrt[2 - c^2]/2, c == 1.2, alpha == 0.7}}, {p}]

I get the following error:

NMaximize::bcons: "The following constraints are not valid: {alpha == 0.7, c == 1.2, c/2 - Sqrt[2 - c^2]/2 < p, p < c/2 + Sqrt[2 - c^2]/2}. Constraints should be equalities, inequalities, or domain specifications involving the variables."

Why is this happening?

$\endgroup$
  • $\begingroup$ c = 1.2; alpha = 0.7; NMaximize[ {(p^2)^alpha + ((c - p)^2)^alpha + (1 - (c - p)^2 - p^2)^ alpha, {c/2 - Sqrt[2 - c^2]/2 < p, p < c/2 + Sqrt[2 - c^2]/2}}, {p}] $\endgroup$ – Dr. belisarius Feb 23 '14 at 21:41
  • $\begingroup$ Plot[(p^2)^alpha + ((c - p)^2)^alpha + (1 - (c - p)^2 - p^2)^alpha, {p, 0, 1}] $\endgroup$ – Dr. belisarius Feb 23 '14 at 21:43
  • $\begingroup$ Thanks for the solution. However, I am still interested as to why my original formulation did not work. $\endgroup$ – gandalfthegreat Feb 23 '14 at 22:11
4
$\begingroup$

Your formulation doesn't work because your constraints don't involve variables. The preferred solution was posted as a comment to your question, but for making your original one work you could do:

NMaximize[{(p^2)^alpha + ((c - p)^2)^alpha + (1 - (c - p)^2 - p^2)^
    alpha, {c/2 - Sqrt[2 - c^2]/2 < p, p < c/2 + Sqrt[2 - c^2]/2, 
   c == 1.2, alpha == 0.7}}, {p, c, alpha}]
(*
  {1.38845, {p -> 0.6, c -> 1.2, alpha -> 0.7}}
*)
$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.