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$
3
  • $\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$ Commented Feb 23, 2014 at 21:41
  • $\begingroup$ Plot[(p^2)^alpha + ((c - p)^2)^alpha + (1 - (c - p)^2 - p^2)^alpha, {p, 0, 1}] $\endgroup$ Commented Feb 23, 2014 at 21:43
  • $\begingroup$ Thanks for the solution. However, I am still interested as to why my original formulation did not work. $\endgroup$ Commented Feb 23, 2014 at 22:11

1 Answer 1

5
$\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 and acknowledge you have read our privacy policy.

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