Question: NLPSolve with an objective function in form of procedure

Hi,

I need to maximize this function:

f := proc(x::Array)
>   if (x[1]^2+x[2]+x[3]+x[4] < 15 and x[1]^2+x[2]+x[3]+x[4] > 10) then
>      2*x[1]^2+3*x[2]+4*x[3]+2*x[4];
>   else
>      1/x[1]+x[2]^2+x[3]+x[4]^2;
>   end if;
> end proc:  

here is the constraint:

> b1:=add(x[i],i=1..4) <= 20;

and initial point:

> initPoint:=[seq(x[i]=1,i=1..4)]:

command for optimization:

> NLPSolve(f,{b1},maximize,initPoint);

There is obviously syntax error but I really don't know how to write it in correct form. I appriciate any help.
 

 

Please Wait...