Assign symbolic variables in objective function as either constants or optimisation variables
이전 댓글 표시
I am trying to optimise an objective function with a mixture of symbolic variables. Some of them are optimisation variables and others are constants. Say I have an objective function to be minimised f(x)=ax^2 + bx +c defined using symbolic variables x, a, b, c. (This is an example - my objective function has more variables and is much longer).
If a,b,c are different constants at each time step I evaluate f(x) at each timestep and minimise it for x . This requires an optimisation for every timestep. Is it possible to define x as an optimisation variable in the objective function and a,b,c as symbolic constants? Then I could minimise the function for x as a function of a,b,c. Then I only need to minimise the generic function once and just substitute values of a,b,c into the solution for each timestep which is obviously much quicker?
Here is an example of my problem:
f = a*x^2 + b*x +c;
gradf = jacobian(f,x).';
hessf = jacobian(gradf,x);
fh = matlabFunction(f,gradf,hessf,'vars',{[x;a;b;c]});
options = optimoptions('fminunc', ...
'SpecifyObjectiveGradient', true, ...
'HessianFcn', 'objective', ...
'Algorithm','trust-region', ...
'Display','off');
x0 = 0;
% I think the issue arises here when I only want to assign a value for one of my symbolic variables (x = x0)
[xfinal,fval,exitflag,output] = fminunc(fh,x0,options); % <- This line errors
Many thanks!
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!