0

The below given constrained function is used in the objective function that is going to be minimized by using fmincon.

fun=@(x) 2*(1-x)*(0.5<=x)*(x<=1)

The objective function is

obj =(c(i).*x(i)+b(i).*quad(fun,l,u))

Due to the function defined in the corresponding interval I get the error:

??? Error using ==> mtimes
Inner matrix dimensions must agree.

Error in ==> @(x)2*(1-x)*(0.5<=x)*(x<=1)
Error in ==> quad at 76
y = f(x, varargin{:});

Caused by:
Failure in initial user-supplied objective
function evaluation. FMINCON cannot continue
Dirk
  • 213

1 Answers1

1

Your function uses matrix multiplication on 3 vectors with identical dimensions, hence is undefined.

You need to use element by element multiplication (.*):

2 .* (1-x) .* (0.5 <= x) .* (x <= 1)

Alternatively, using a transpose would accomplish the same result.

ocstl
  • 136