How to use fmincon on an symbolic integral function

조회 수: 3 (최근 30일)
Sylvia1008
Sylvia1008 2016년 11월 1일
편집: Sylvia1008 2016년 11월 1일
Update: just rewrote my question... should be clear now...
I was trying to use fmincon to find the optimizer x=[x(1),x(2)] of a integral function where x(1) and x(2) are in the expression of the lower and higher limits of the integral, but I failed a lot of attempts which has driven me crazy!!!! Could someone help? A simple example to illustrate my problem, I want to find values for x and y to minimize function: integral(z^2,x,y)=(y^3)/3-(x^3)/3, such that 0<=x<=1,2<=y<=5.
Below are the code I wrote:
fun=@(x,y) int(@(z) z^2,x,y);
a0=[0,0];
sol=fmincon(fun,a0,[],[],[],[],[0,2],[1,5]);
Of course the code does not work and feedbacks are:
Error using symengine>makeFhandle/@(x,y)x.^3.*(-1.0./3.0)+y.^3.*(1.0./3.0) Not enough input arguments.
Error in fmincon (line 564)
initVals.f = feval(funfcn{3},X,varargin{:});
Error in test (line 12)
sol=fmincon(ht,a0,[-1,-1],0)
Caused by:
Failure in initial user-supplied objective function evaluation.
FMINCON cannot continue.

답변 (3개)

Mischa Kim
Mischa Kim 2016년 11월 1일
Sylvia, use integral2 in combination with fmincon.
  댓글 수: 1
Sylvia1008
Sylvia1008 2016년 11월 1일
Thank you, but can you show me how? I don't see how that's the key problem I'm facing...

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


Walter Roberson
Walter Roberson 2016년 11월 1일
fun = @(xy) integral(@(z) z^2, xy(1), xy(2));
a0 = [0,0];
sol = fmincon(fun,a0,[-1,-1],0);

Alan Weiss
Alan Weiss 2016년 11월 1일
I do not understand your example, but perhaps a completely new start will help you. Suppose that you have a parameterized function of x and y, say with parameter a:
f = sin(a*x.^3)./3 - cos(a*y.^3)./3
Suppose that you want to minimize the integral of this function over 0 <= x <= 1, 1 <= y <= 2, and for -5 <= a <= 1.
fun = @(a)integral2(@(x,y)sin(a*x.^3)./3 - cos(a*y.^3)./3,0,1,1,2);
[asolution,intval] = fminbnd(fun,-5,1)
asolution =
-3.3592
intval =
-0.1405
You see, I defined the objective function of a as an integral, and found the minimum value of the integral over values of a in the interval -5 <= a <= 1.
Alan Weiss
MATLAB mathematical toolbox documentation

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by