fmincon optimization with integral function

조회 수: 6 (최근 30일)
SG
SG 2018년 7월 30일
답변: Walter Roberson 2018년 7월 30일
I'm trying to minimize the area of a function using fmincon and integral function My function is as given below
func = @(x)integral((@(l)(x(1)-l)),x(2),x(3),'ArrayValued',true);
...
[x, fval] = fmincon(func,x0,A,b,Aeq,beq,lb,ub,nonlcon);
The error I'm seeing is -
Input arguments to function include colon operator. To input the colon character, use ':' instead.
Error in fmincon (line 635) initVals.nceq = ceqtmp(:);
Error in flattop (line 15) [x, fval] = fmincon(func,x0,A,b,Aeq,beq,lb,ub,nonlcon);
Error in Load_Shift_Flat (line 118) [pnew, tstart, tending] = flattop(peak_load,tsta,tend,pmax,e(i-1));
I'm trying to optimize for 3 variables and l is an array which is an input to the flattop function
  댓글 수: 2
Walter Roberson
Walter Roberson 2018년 7월 30일
It looks like the problem is in your nonlcon. What have you passed there?
The error would be consistent with your nonlcon returning a function handle when a value is expected.
SG
SG 2018년 7월 30일
So it is a function which uses 2 global variables from the workspace
function [c,ceq] = areaunderc(x)
global ene;
global l;
energ = ene;
c = [];
ceq = @(x)integral(@(l)(l - x(1)),x(2),x(3)) - energ;
end

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2018년 7월 30일
Remove the @(x) in the definition of ceq in your nonlcon. You are returning a handle to a function where you need to return a definite value for the current input.

추가 답변 (0개)

제품


릴리스

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by