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 | //gauss elimination that makes m to upper triangular inline void u_m(mxd::r _m , vxd::r _v){ i::t idx = 0; while(idx < _m.rows()){ mxd::b A00 = _m.block(0 , 0 , idx , idx ); mxd::b a10 = _m.block(idx , 0 , 1 , idx ); mxd::b A20 = _m.block(idx + 1, 0 , _m .rows() - (idx + 1) , idx ); mxd::b a01 = _m.block(0 , idx , idx , 1 ); mxd::b alpha11 = _m.block(idx , idx , 1 , 1 ); mxd::b a21 = _m.block(idx + 1, idx , _m.rows() - (idx + 1) , 1 ); mxd::b A02 = _m.block(0 , idx + 1 , idx , _m.cols() - (idx + 1) ); mxd::b a12 = _m.block(idx , idx + 1 , 1 , _m.cols() - (idx + 1) ); mxd::b A22 = _m.block(idx + 1, idx + 1 , _m.rows() - (idx + 1) , _m.cols() - (idx + 1) ); vxd::b b0 = _v.segment(0 , idx ); vxd::b betha1 = _v.segment(idx , 1 ); vxd::b b2 = _v.segment(idx + 1 , _v.rows() - (idx + 1) ); a21 = a21 / alpha11.value(); A22 = A22 - a21 * a12; b2 = b2 - betha1.value() * a21; idx++; } } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 | mxd::t m2(3,3); m2 << 2, 4, -2, 4,-2, 6, 6,-4, 2; vxd::t v(3); v << -10, 20, 18; u_m(m2,v); co(m2); co(v); | cs |
1 2 3 4 5 6 7 8 | output = 2 4 -2 2 -10 10 3 1.6 -8 output = -10 40 -16 | cs |
'Linear Algebra' 카테고리의 다른 글
[Eigen] Day 9. solving triangular matrix (0) | 2019.06.02 |
---|---|
[Eigen] Day 9. LU decomposition (0) | 2019.06.02 |
[Eigen] Day 8. special matrix and vector multiplication (0) | 2019.06.01 |
[Eigen] Day 8. matrix multiplication and it's application : predicting the weather (0) | 2019.06.01 |
[Eigen] Day 8. slicing and redicing with matrix and vector multiplication (0) | 2019.06.01 |