chaptor 3-1 practice
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | //chaptor 3-1 practice v3d::t u; v3d::t v; v3d::t w; u << -2, 0, 4 ; v << 3, -1, 6 ; w << 2, -5, -5 ; //define 3v - 2u co( 3 * v - 2 * u, "a)" ); //define ||u + v + w|| co( (u + v + w).norm() , "b" ); //define vector -3u to w(v+5) co( d_poToPo(-3 * u, v + 5 * w ), "c" ); //define proj vector u on w co( v_proj(u,w), "d" ); | cs |
implementing linear combination algorithm
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 | //linear combination with a recursive method inline vxd::t v_comb(mxd::t _v, vxd::t coefficient, int _dimention, int acc = 0){ if(acc == _dimention){ return VectorXd(_v.cols()).setZero(); } return v_comb(_v, coefficient, _dimention, ++acc) + (_v.col(acc) * coefficient[acc]); } //linear combination with a for-statement inline vxd::t v_comb(mxd::t _v, vxd::t coefficients){ vxd::t v_(_v.cols()); v_.setZero(); for(z::t i(0) ; i < _v.cols() ; ++i){ v_ = v_ + _v.col(i) * coefficients[i]; } return v_; } //inner product( dot product) inline double d_dot(vxd::t _v1, vxd::t _v2 , int _dim){ if(_dim == -1) return 0; return _v1[_dim] * _v2[_dim] + d_dot(_v1, _v2 , --_dim); } | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | vxd::t v(3); mxd::t m(3,3); m << 1,2,3, 1,2,3, 1,2,3; v << 10, 20, 30; co(v_comb(m, v, 3)); co(v_comb(m,v)); output = 140 140 140 output = 140 140 140 | cs |
implementing dot product algorithm
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | //inner product( dot product) inline double d_dot(vxd::t _v1, vxd::t _v2 , int _dim , int acc = 0){ if( acc == _dim ) return 0; return _v1[acc] * _v2[acc] + d_dot(_v1, _v2 , _dim, ++acc); } v << 1,1,0; v2 << 3,1,1; co( d_dot(v,v2,v.rows() )); output = 4 | cs |
'Linear Algebra' 카테고리의 다른 글
[Eigen] reviewing linear algebra day5. zero matrix with slicing and redicing (0) | 2019.05.27 |
---|---|
[Eigen] reviewing linear algebra day.4 , slicing and redicing (0) | 2019.05.26 |
[Eigen] 복습 2일차 (0) | 2019.05.22 |
[Eigen] 아이겐을 사용한 선형대수 복습 1일차 (0) | 2019.05.21 |
[Eigen] extracting a vector from the vector space (0) | 2019.05.21 |