# How can a constrained function in an objective function be used with fmincon in matlab? [closed]

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


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