Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
    
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}] –  belisarius Feb 23 at 21:41
    
Plot[(p^2)^alpha + ((c - p)^2)^alpha + (1 - (c - p)^2 - p^2)^alpha, {p, 0, 1}] –  belisarius Feb 23 at 21:43
    
Thanks for the solution. However, I am still interested as to why my original formulation did not work. –  gandalfthegreat Feb 23 at 22:11
add comment

1 Answer 1

up vote 4 down vote accepted

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}}
*)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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