sooprise
sooprise

Reputation: 23187

Minimizing a multivariable function

I'm aware of the fminsearch function, but it only seems to be able to solve for one variable.

If my function looks like f(x,y,z) and I want to find the values of x,y,z that gives the lowest result, how would I do this in MatLab? The complexity of f would make it unreasonably difficult to calculate the partial derivatives.

Any help would be appreciated, thanks!

Upvotes: 1

Views: 9440

Answers (1)

pseudoDust
pseudoDust

Reputation: 1386

fminsearch is multivariable, for example:

a = fminsearch(@(x)((x(1)-1)^2+(x(2)-2)^2), [0,0]);

the parameter passed to the objective function can be a vector, just be sure to specify the x0 parameter (the second parameter in fminsearch) to the right size.

Upvotes: 8

Related Questions