0
$\begingroup$

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
$\endgroup$
1
$\begingroup$

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.

$\endgroup$
  • 1
    $\begingroup$ It worked, thx ! $\endgroup$ – Dirk Sep 13 '15 at 11:37

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