-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_qprogramieq.m
More file actions
53 lines (46 loc) · 926 Bytes
/
Copy pathtest_qprogramieq.m
File metadata and controls
53 lines (46 loc) · 926 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#
function test_qprogramieq()
# f = ((x-xc)^2 + (y-yc)^2)/2
# = (x^2 + y^2 - 2*xc*x - 2*yc*y + xc^2 + yc^2)/2
# = [x y]*I*[x; y]/2 - [x y]*[xc; yc] + b^2/2
# A = I(2), b = -[xc; yc]
A = [
1, 0;
0, 1];
b = -[
1;
1];
f = @(x)(x'*A*x + x'*b*2 + b'*b)/2;
# x <= 1
# y <= 1
# x >= 0
# y >= 0
# x+y <= 1.5
# x+y >= 0.5
Ci = [
1, 0;
0, 1;
-1, 0;
0,-1;
1, 1];
di = [
1;
1;
0;
0;
1.5];
max_iter = 1000;
tol = 1e-10;
x = [0; 0];
printf("---- Quadratic Programming: Active Set method ----\n");
[x, iter, xs] = qprogramieq(A, b, Ci, di, x, tol, max_iter);
printf("x_sol = (%f, %f)\n", x(1), x(2));
printf("|f(x_sol)| = %f\n", f(x));
printf("iterations: %d\n", iter);
plot(xs(1,:), xs(2,:), ...
"color", "k", ...
"marker", ".", ...
"markersize", 15, ...
"linestyle", "-", ...
"linewidth", 2);
endfunction