Hi all,

I wanna use integral function in cvx instead of fmincon in matlab.

here is a simple example.

3 case

Case.1 : fmincon with integral ( work )

Case.2 : cvx without integral ( work ), handed calculation

Case.3 : cvx with integral ( doesn’t work )

how can I change it?

% Case.1 : fmincon with integral ( work )

x0 = 0;

A = 1; b = 40; %constraint Ax <= b

fun = @(x)func(x);

[x optval] = fmincon(fun,x0,A,b)

function result = func(x)

func_temp =@(y) -x+4+y;

result=integral(func_temp,-5,5);

end

%optval = -360

%x = 40

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Case.2 : cvx without integral ( work )

cvx_begin quiet

variable x

minimize(func(x))

x <= 40 %constraint Ax <= b

cvx_end %result => x and cvx_optval

opt_val = cvx_optval

x’

function result = func(x)

result = -10*x+40; % handed calculation

end

%optval = -360

%x = 40

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Case.3 : cvx with integral ( doesn’t work )

cvx_begin quiet

variable x

minimize(func(x))

x <= 40 %constraint Ax <= b

cvx_end %result => x and cvx_optval

opt_val = cvx_optval

x’

function result = func(x)

func_temp =@(y) -x+4+y;

result=integral(func_temp,-5,5);

end