1

I need to maximize the following objective function in Matlab:

mean (a*I'*x1+b*(ones(1,24)-I)'*x1)-mean((a*(ones(1,24)-I)'*y1)+(b*I'*y1))

I made two .m file:

  1. In the objfun.m file I defined the objective function as:

    function f = objfun(x)
    f = mean (a*I'*x1+b*(ones(1,24)-I)'*x1)-mean((a*(ones(1,24)-I)'*y1)+(b*I'*y1));
    
  2. In the second (main) .m file I have my parameters and calculations for a, b and I and also below constraints and fmincon:

    lb = [0,0];
    ub = [10,10];
    x0 = [1,2];
    [x,fval] = fmincon(@objfun,x0,[],[],[],[],lb,ub)
    

When I run the program I get below error for fmincon:

Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.

Would you please advise how can I fix this problem? Is there anything wrong with my objective function, as it is a function of x1 and y1 but I have objfun(x) only? Or do I call the function wrongly? Any help is appreciated!

m7913d
  • 10,244
  • 7
  • 28
  • 56
Sara
  • 47
  • 2
  • Your objective function definition is not correct, i.e. you should define all your variables. – m7913d Jun 21 '17 at 20:40
  • Possible duplicate of [Constrained minimization in MATLAB](https://stackoverflow.com/questions/44464008/constrained-minimization-in-matlab) – m7913d Jun 21 '17 at 20:41
  • 1
    You didn't define `a`, `I`, `x1`, `b`, and `y1` – Sardar Usama Jun 21 '17 at 20:41
  • I defined a and b in my main.m file which are 1x24 vectors with constant values. x1 and y1 are defined as x1 = sym('x', [1 24]); y1 = sym('y', [1 24]); but still fmincon does not work. Also I tried with changing lb, ub,x0 dimensions to 24x1 vectors, but still I get the same error. – Sara Jun 22 '17 at 20:54

0 Answers0