How to use fmincon on an symbolic integral function

3 次查看(过去 30 天)
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.

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