Symbolic Mathematics with Optimization Toolbox Solvers

3 次查看(过去 30 天)
In this http://www.mathworks.com/help/optim/examples/using-symbolic-mathematics-with-optimization-toolbox-solvers.html is given the documentation for using Symbolic Mathematics with Optimization Toolbox Solvers. The first example is this:
syms x1 x2 real
x = [x1;x2]; % column vector of symbolic variables
f = log(1 + 3*(x2 - (x1^3 - x1))^2 + (x1 - 4/3)^2);
gradf = jacobian(f,x).'; % column gradf
hessf = jacobian(gradf,x);
fh = matlabFunction(f,gradf,hessf,'vars',{x});
options = optimset('GradObj','on','Hessian','on', ...
'Display','final');
[xfinal fval exitflag output] = fminunc(fh,[-1;2],options)
The function handle fh that is created accepts one matrix input which is:
in1(1,:)
in1(2,:)
The optimization used in the example did not require any constraints. However if constraints were necessary then they should be given in the form of a two dimensional matrix.
The constraints in the example would require a 3 dimensional matrix to be defined. But then the optimization would not be able to be executed since the solvers accept 2 dimensional matrices.
My question is how must the matlabFunction be written in order to create a function handle which would accept as an input variable a vector of x, such as:
in1(1)
in1(2)
Thank you

回答(2 个)

Giorgos Papakonstantinou
编辑:Giorgos Papakonstantinou 2013-2-1
What? It cannot be done???

Alan Weiss
Alan Weiss 2013-2-1
You will find the answer to your questions in another documentation example.
Alan Weiss
MATLAB mathematical toolbox documentation

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by