Hi,
I've tried using rmatrixsolvels on my system of linear equations, but I do not understand the results.
E.g. Equation 0 states that rx[0] + rx[1] = 1, but in the results rx[0]=0.385714 and rx[1]=0.414286 (which clearly is !=1)
Help is much appreciated.
Sunaj
Code:
Code:
void testSolveLinEq() {
alglib::real_2d_array m;
alglib::real_1d_array r;
int nx = 11;
int ny = 10;
m.setlength(ny,nx);
for (int x=0;x<nx;x++)
for (int y=0;y<ny;y++)
m[y][x] = 0;
m[0][0] = 1; m[0][1] = 1;
m[1][1] = -1; m[1][3] = 1;
m[2][0] = -1; m[2][2] = 1;
m[3][3] = -1; m[3][6] = 1;
m[4][5] = 1; m[4][6] = -1; m[4][8] = 1;
m[5][2] = -1; m[5][4] = 1; m[5][5] = -1;
m[6][4] = -1; m[6][7] = 1;
m[7][8] = -1; m[7][10] = 1;
m[8][9] = 1; m[8][10] = -1;
m[9][7] = -1; m[9][9] = -1;
r.setlength(ny);
r[0] = 1;
r[1] = 0;
r[2] = 0;
r[3] = 0;
r[4] = 0;
r[5] = 0;
r[6] = 0;
r[7] = 0;
r[8] = 0.5;
r[9] = 0.5;
alglib::real_1d_array rx;
alglib::ae_int_t info;
alglib::densesolverlsreport rep;
alglib::rmatrixsolvels(m,ny,nx,r,0.0,info,rep,rx);
for (int x=0;x<nx;x++) cout << "rx[" << x << "]=" << rx[x] << endl;
}
Results:
rx[0]=0.385714
rx[1]=0.414286
rx[2]=0.185714
rx[3]=0.214286
rx[4]=-0.0857143
rx[5]=-0.0714286
rx[6]=0.0142857
rx[7]=-0.285714
rx[8]=-0.114286
rx[9]=-0.0142857
rx[10]=-0.314286