Optimization toolbox-fmincon error-
4 次查看(过去 30 天)
显示 更早的评论
Hello everybody
I'm trying to minimize a multivariable expression using fmincon under constrain. To introduce you more precisely the problem. I want to find the normal vector u of the best fitting plan which describe the most precisely a set of data from a marker placed on a rat knee. And for this I use an optimization method. But it doesn't work... My matlab version is R2012b
The expression to minimize is:
function [f] = Functiofun(S)
syms x y z
u=[x;y;z];
f=u'*S*u;
end
were S is a matrix using data of the marker and this returns:
f =
x*((4919489910730857*conj(x))/549755813888 + (1885243380871159*conj(y))/274877906944 - (1356072232583407*conj(z))/549755813888) - z*((1356072232583407*conj(x))/549755813888 + (4128876282184185*conj(y))/2199023255552 - (3333614421791133*conj(z))/137438953472) + y*((1885243380871159*conj(x))/274877906944 + (924159128957421*conj(y))/68719476736 - (4128876282184185*conj(z))/2199023255552)
Hence I want to minimize this function under the following constrain:
function [g] = Functionfun_g(C)
syms x y z
u=[x;y;z];
g=u'*C*u-1;
end
which is simply normalisation of my output vector
g =
x*conj(x) + y*conj(y) + z*conj(z) - 1
so I wrote the following code sentence using fmincon:
x0=[0;0;0]
options = optimset('Algorithm','sqp');
[x,fval] = fmincon(f,x0,[],[],[],[],[],[],...
g,options);
And it returns me this error:
Error using optimfcnchk (line 288)
If FUN is a MATLAB object, it must have an feval method.
Error in fmincon (line 423)
funfcn =
optimfcnchk(FUN,'fmincon',length(varargin),funValCheck,flags.grad,flags.hess,false,Algorithm);
.... I need help please :)
0 个评论
回答(2 个)
Igor
2014-5-1
You can't pass symbolic variables as functions to 'fmincon'. Use 'matlabFunction' to convert your symbolic functions to function handles: http://www.mathworks.com/help/symbolic/matlabfunction.html
Good luck
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!