Interior-point and sequential quadratic programming give me the same answer. Is there an error with my code?
Show older comments
I am attempting to minimise a least squares regression model and compare answers given by SQP and IP, and the system is constrained by x(1) + x(2) + x(3) = 1, and each variable cannot be smaller than 0 or bigger than 1. However, I consistently get the same numerical answers for both methods, which should not be the case. I am wondering if I missed a step or something along those lines? My code is as follows;
fun=@(x) (x(1)-147/505).^2+(x(1)-167/530).^2+(x(2)-504/2525).^2+(x(2)-471/2120).^2+(x(3)-1011/2120).^2+(x(3)-1256/2525).^2;
x0=[0.3, 0.5, 0.2];
Aeq=[1, 1, 1];
beq=1;
lb=[0, 0, 0];
ub=[1, 1, 1];
IP=fmincon(fun,x0,[],[],Aeq,beq,lb,ub);
fprintf('%.13f\n',IP)
options = optimoptions('fmincon','Algorithm','sqp');
SQP=fmincon(fun,x0,[],[],Aeq,beq,lb,ub);
fprintf('%.13f\n',SQP)
These are my results;
IP:
0.3027134331491
0.2105086010671
0.4867779657839
SQP:
0.3027134331491
0.2105086010671
0.4867779657839
Any help or pointers would be appreciated. Thank you in advance.
4 Comments
Torsten
on 13 Nov 2023
However, I consistently get the same numerical answers for both methods, which should not be the case.
Why ?
Aisel
on 13 Nov 2023
Torsten
on 13 Nov 2023
Maybe one needs more iterations with one of the methods (use 'Display','iter' in the options structure). But if you prescribe the accuracy of the solution to be equal for both methods (as you implicitly do in your code because you didn't change them in the optimoptions structure), in theory both solutions should be equally precise, shouldn't they ?
Aisel
on 13 Nov 2023
Accepted Answer
More Answers (0)
Categories
Find more on Linear Least Squares in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!