Tuesday 15 July 2014

matlab - Unconstrained nonlinear optimization function -



matlab - Unconstrained nonlinear optimization function -

i want optimize unconstrained multivariable problem using fminunc function in matlab. here example:

minimize function f(w)=x'ax

create file myfun.m:

function f = myfun(x) f = x'*a*x + b'x

then phone call fminunc find minimum of myfun near x0:

[x,fval] = fminunc(@myfun,x0).

my problem in algorithm, matrix a , vector b in myfun.m not fixed, can changed on loops, cannot type them hand. how can pass values a , b?

there few options passing additional arguments objective function. simple 1 yours, create anonymous function, save values of a , b when created:

a = mymata(); b = myvecb(); myfun = @(x) x.'*a*x + b.'*x; [x,fval] = fminunc(myfun,x0); % utilize no @ anonymous function

the other 2 options global variables (yuck!) , nested functions. nested function version looks this:

function [x,fval] = myopt(a,b,x0) [x,fval] = fminunc(@myfunnested,x0); function y = myfunnested(x) y = x.'*a*x + b.'*x; end end

but think not utilize fminunc solve minimization of x'ax + b'x...

matlab

No comments:

Post a Comment