MATLAB Answers

How to use fminunc for more than one variable

38 views (last 30 days)
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);
end
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:
>>computeCostMulti(tSet,profit,theta)
ans =
623.5855
I really stucked here.
Whats the right way to do this?
Tks in advance

  0 Comments

Sign in to comment.

Accepted Answer

Leonardo Hermoso
Leonardo Hermoso on 16 May 2013
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!

  0 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!