Boost's Linear Algebra Solution for y=Ax

前端 未结 6 1497
感动是毒
感动是毒 2020-12-29 13:24

Does boost have one? Where A, y and x is a matrix (sparse and can be very large) and vectors respectively. Either y or x can be unknown.

I can\'t seem to find it her

6条回答
  •  感动是毒
    2020-12-29 13:55

    yes, you can solve linear equations with boost's ublas library. Here is one short way using LU-factorize and back-substituting to get the inverse:

    using namespace boost::ublas;
    
    Ainv = identity_matrix(A.size1());
    permutation_matrix pm(A.size1());
    lu_factorize(A,pm)
    lu_substitute(A, pm, Ainv);
    

    So to solve a linear system Ax=y, you would solve the equation trans(A)Ax=trans(A)y by taking the inverse of (trans(A)A)^-1 to get x: x = (trans(A)A)^-1Ay.

提交回复
热议问题