0
$\begingroup$

So I want to use fminunc(fun, X0) in Matlab on my function fun. The problem is that fun is a function of three parameters:(X, y, X0), all of which are vectors. What I want to do is to find the minimum, given the parameters X, y. I.e. the vector X0 which minimises the function for some given values X, y. How would I go about doing this?

$\endgroup$
1
$\begingroup$

What we have here is a function fun(X, y, X0) and fminunc(fun,X0). You know X, and y, lets call them X* and y*, so we could replace fun(...) by fun*(X0)

% function to be minized
fun = @(X, y, X0) (dot(X,y) + X0)^2   
X_star = [1,2,3]
y_star = [4,5,6]
$ same function but with X and y filled in
fun_star = @(X0) fun(X_star, y_star, X0) 
X0_star = 0
fminunc(fun_star, X0) 
$\endgroup$
1
  • $\begingroup$ Oh those anonymous functions. Thanks for reminding me why I switched to R. Gotta run -- only 2 more fortnights until my model converges! $\endgroup$ – HEITZ Oct 13 '16 at 22:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.