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!