In Matlab, you can use the fminsearch
or fminunc
functions to find local extrema of a multivariable function. Here's an example:
main.m280 chars13 lines
In this example, we define a function f
that takes a 2-element vector as input and returns a scalar value. We then use fminsearch
to find the input that minimizes f
. The function fminunc
works similarly, but can handle more complex functions and allows for more options to be specified.
Note that these functions only find local extrema, and may not find the global minimum. To improve the chances of finding the global minimum, you can try running these functions with multiple initial guesses.
gistlibby LogSnag