To minimize a function in Matlab, you can use the built-in function fminsearch
. This function finds the minimum of a scalar function of one or more variables using the Nelder-Mead simplex algorithm.
Here is an example of how to use fminsearch
to minimize a simple function:
main.m276 chars12 lines
In this example, the function being minimized is f(x) = x1^2 + x2^2
, and we are starting the optimization at the point (1, 1)
. The fminsearch
function returns the point (0, 0)
, which is the minimum of the function.
Note that in order to use fminsearch
, you need to define your function as an anonymous function (using @(x)
), and the input must be a vector x
.
gistlibby LogSnag