optimproblem does not solve an analytical equation correct
2 views (last 30 days)
Show older comments
Gabriel Waibel
on 10 May 2023
Commented: Gabriel Waibel
on 10 May 2023
Dear Matlab,
I am using optimproblem to solve a overdetermined optimization problem. Since the results were completly wrong I tried the follow problem which has a unique solution. Also there the result is extremly wrong.
I have a rectangle, each side determined by two points. I would like to get the constant and the normal vector of each side. Therefore I set up the optimization problem as follows.
% points for each side of the rectangle
Px = [0;1]
Py = [1;1]
Qx = [1;1]
Qy = [1;0]
Rx = [1;0]
Ry = [0;0]
Sx = [0;0]
Sy = [0;1]
zp = zeros(size(Px)); op = ones(size(Px));
zq = zeros(size(Qx)); oq = ones(size(Qx));
zr = zeros(size(Rx)); or = ones(size(Rx));
zs = zeros(size(Sx)); os = ones(size(Sx));
A = [ op zp zp zp Px Py
zq oq zq zq Qy -Qx
zr zr or zr Rx Ry
zs zs zs os Sy -Sx]
c1 = optimvar('c1');
c2 = optimvar('c2');
c3 = optimvar('c3');
c4 = optimvar('c4');
n1 = optimvar('n1');
n2 = optimvar('n2');
optivars = [c1; c2; c3; c4; n1; n2];
prob = optimproblem;
prob.Objective = (A*optivars).'*(A*optivars);
prob.Constraints.con1 = n1*n1 + n2*n2 == 1;
show(prob)
init_value.c1 = -1.0;
init_value.c2 = 1.0;
init_value.c3 = 0.0;
init_value.c4 = 0.0;
init_value.n1 = 0.0;
init_value.n2 = 1.0;
[sol,fval,exitflag] = solve(prob, init_value);
If I do show(prob) I get the output of the optimization problem. The equations are correct and if I solve them by hand the result is correct. So why does solve(prob,init_value) not find the solution even with the perfect inital condition? I also get 70 values for each variable (c1,c2,c3,c4,n1,n2)?
Thanks
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Quadratic Programming and Cone Programming 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!