Optimization toolbox-fmincon error-

13 views (last 30 days)
Victor Moranville
Victor Moranville on 1 May 2014
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 :)

Answers (2)

Igor
Igor on 1 May 2014
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

Victor Moranville
Victor Moranville on 2 May 2014
Hello
I found the mistake and as you said it was a function problem declaration I wrote it as following:
[S,C]=Matrix_C_S(D)
options = optimset('Algorithm','sqp','MaxIter',2000);
x0=[1;1;1;1;1]
[x, k] = fmincon(@(x)([x(1),x(2),x(3),x(4),x(5)]*(S*[x(1);x(2);x(3);x(4);x(5)])),x0,[],[],[],[],[],[],...
@confuneq,options);options = optimset('Algorithm','sqp','MaxIter',2000);
x
;)
Danke Shoën

Categories

Find more on Get Started with Optimization Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!