Non-linear Optimization with summation objective function and data set
이전 댓글 표시
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
Ameer Hamza
2020년 4월 20일
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
2020년 4월 20일
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.
채택된 답변
추가 답변 (1개)
MP
2020년 4월 20일
0 개 추천
댓글 수: 1
Ameer Hamza
2020년 4월 20일
편집: Ameer Hamza
2020년 4월 20일
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
카테고리
도움말 센터 및 File Exchange에서 Genetic Algorithm에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!