Non-linear Optimization with summation objective function and data set
Mostrar comentarios más antiguos
Hello,
I'm looking for someone to help me implement a non linear optimization problem with one constraint and a dataset.
The objective function is a mult-summation NLP
The constraint is:
The dataset x is a vector with two columns, where x( i) = column 1 and x(j) = column 2. Both x(i) and x(j) map to dataset y(i) and y(j), respectively. Variable p(i) and p(j) is unknown.
How do I formulate a NLP problem in MATLAB to solve for the different iterations of p(i) and p(j)?
3 comentarios
Ameer Hamza
el 20 de Abr. de 2020
What is the dimension of 'x' and 'y'? Are they 4x2 matrices? If they have two columns, then how do you distinguish between two columns, for example, what is the column for x(1), x(2), x(3), ...? What are the dimensions of 'p'?
Ameer Hamza
el 20 de Abr. de 2020
You mentioned x(i) is same as x(i,1). Then which variable will corresponds to column 2. I suggest to re-write the equation show the difference between columns and rows of matrix x and y.
Respuesta aceptada
Más respuestas (1)
MP
el 20 de Abr. de 2020
0 votos
1 comentario
Ameer Hamza
el 20 de Abr. de 2020
Editada: Ameer Hamza
el 20 de Abr. de 2020
1. Yes, that will also work. I guess the only difference is that the function might take longer because in implementation, when A and B are specified, MATLAB knows that these are linear constraints so It can apply optimized methods. But using constraint function, it will consider then to be a nonlinear constraint that might require more effort to solve. Nevertheless, the results should be similar.
2. Yes, it is also possible. You can use the outputFcn property of fmincon to do anything at the end of an iteration. See here, for example: https://www.mathworks.com/help/optim/ug/output-functions.html and here for more details: https://www.mathworks.com/help/optim/ug/output-function.html. I wrote a simple example to illustrate the concept.
f = @(x) sum(x.^2.*exp(-x.^2)); % objective function
opts = optimoptions('fmincon', 'OutputFcn', @myOutFcn, 'Display', 'off');
[x_sol, f_sol] = fmincon(f, rand(10,1), [], [], [], [], [], [], [], opts);
function stop = myOutFcn(x, optimValues, state)
persistent i
if isempty(i)
i = 1;
end
fprintf('Iteration: %d, Objective function value: %.16f\n', i, optimValues.fval)
i = i+1;
stop = 0;
end
Categorías
Más información sobre Genetic Algorithm en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!