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!