Assign symbolic variables in objective function as either constants or optimisation variables
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Greg Jones
el 7 de Abr. de 2020
Comentada: Greg Jones
el 7 de Abr. de 2020
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 comentarios
Respuesta aceptada
Steven Lord
el 7 de Abr. de 2020
Let's treat a as a symbolic constant and examine a slightly simpler version of your function. What's the minimum value the function f(x) = a*x.^2 takes over the interval [-1, 1] and at which value of x does that minimum occur?
If you said the minimum value was f(x) = 0 when x = 0, you're at best partially right.
If a is negative, the minimum value is f(x) = a at either of the endpoints.
The output of the objective function you pass into fminunc cannot be a symbolic expression in part because of situations like the one I described above.
Más respuestas (0)
Ver también
Categorías
Más información sobre Calculus en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!