MATLAB: How to use fminunc for more than one variable

MATLABoptimizationOptimization Toolbox

Hello guys,
I'm try to minime the cost of a function using fminunc
i have a function cost:
function J = computeCostMulti(X, y, theta);
J = 1/(2*size(y,1)) * sum(((X * theta)-y).^2);
So i try :
if true
[optTheta,fVal]= fminunc(@computeCostMulti,tSet,profit,theta,options);
And got:
Warning: Struct field assignment overwrites a value with class "double". See MATLAB R14SP2 Release Notes, Assigning Nonstructure Variables As Structures Displays Warning, for details. > In fminunc at 200 Undefined function 'mtimes' for input arguments of type 'struct'. Error in computeCostMulti (line 16) T = 1/(2*size(y,1)) * sum(((X * theta)-y).^2); Error in fminunc (line 251) f = feval(funfcn{3},x,varargin{:}); Caused by: Failure in initial user-supplied objective function evaluation. FMINUNC cannot continue.
if i call computeCostMulti:
ans =
I really stucked here.
Whats the right way to do this?
Tks in advance

Best Answer

I solved my problem using anon functions
so i did:
f = @(x,y,z) function(tSet,preco,theta)
[optTheta, fVal, exit] = fmiunc(f,tSet,preco,theta,options);
And it's run!