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?
Asked
Active
Viewed 147 times
1 Answers
1
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)

Laurens Meeus
- 619
- 3
- 10
-
Oh those anonymous functions. Thanks for reminding me why I switched to R. Gotta run -- only 2 more fortnights until my model converges! – HEITZ Oct 13 '16 at 22:32