Matlab has several built-in functions to find the extremum of a multivariable function. One of the popular ones is the fmincon
function which finds the minimum of a multivariable function subject to constraints.
Here's an example code that finds the minimum of a function f
with initial guess x0
and lower and upper bounds for x
:
main.m406 chars18 lines
In this example, the function f
is (x(1)-2)^2 + (x(2)-3)^2
, and we are finding the minimum value of f
subject to lower and upper bounds on the variables x(1)
and x(2)
. The initial guess is [1;1]
, and the fmincon
function is called with the options Display
set to iter
to display the optimization process.
The function returns the optimal value of x
and the minimum value of the function f
.
gistlibby LogSnag