I have read the document and the example QP, but I’m not quite sure whether the Hessian matrix(P matrix) is setup as upper-triangular matrix or lower-triangular matrix, it seems that it is set up as upper-triangular matrix, according to the data filled in row indices P_i and column pointers P_p. Someone please tell me which one is true.

Another question, are all matrices in column-major form or row-major form?

Upper triangular. Sparse matrices are in compressed sparse column format.

1 Like

Thanks, one more question, for each of the column pointers in the p[] array, if that column is all zeros, then what will the pointer be? Pointing to the tail of the array?

Consecutive elements in the p array can be thought of as the position of the start of each column and one past the end. A repeated entry indicates an empty column.

1 Like

Hello

Hopefully it is OK to revive this topic. But I think my problem fits here.

I am trying to setup a problem in c which I already solved (res.x = [-0.14, -0.36, 0.05]) in Matlab.

P = sparse([4, 0.1 0.1; 0.1, 2, 0.1; 0.1, 0.1, 3]);
q = [1; 1; -0.1];
A = sparse([1, 0, 0; 0, 1, 0; 1, 1, 0]);
l = [-0.14; -0.4; -0.5];
u = [ 0.14; 0.4; -0.5];

p = osqp;
p.setup(P, q, A, l, u, ‘alpha’, 1);
res = p.solve();

I tried to set up the same problem in c and it puzzles me. I started with the example ‘Setup and Solve’ from the homepage, compiled it ran it and got a solution. Then I changed the problem setup to the following lines.

c_int n = 3;
c_float P_x[6] = {4.0, 0.1, 2.0, 0.1, 0.1, 3.0,};
c_int P_nnz = 6;
c_int P_i[6] = {0, 0, 1, 0, 1, 2, };
c_int P_p[4] = {0, 1, 3, 6, };

c_float q[3] = {1.0, 1.0, -0.1,};
c_int m = 3;

c_int A_nnz = 4;
c_float A_x[4] = {1.0, 1.0, 1.0, 1.0, };
c_int A_i[4] = {0, 2, 1, 2, };
c_int A_p[3] = {0, 2, 4, };

c_float l[3] = {-0.14, -0.4, -0.5, };
c_float u[3] = { 0.14, 0.5, -0.5, };

May somebody can see my mistake?

You should have `c_int A_p[4] = { 0, 2, 4, 4, };`