Skip to content
Snippets Groups Projects
cs_lusol.c 873 B
Newer Older
  • Learn to ignore specific revisions
  • Lubomir Riha's avatar
    Lubomir Riha committed
    #include "cs.h"
    /* x=A\b where A is unsymmetric; b overwritten with solution */
    CS_INT cs_lusol (CS_INT order, const cs *A, CS_ENTRY *b, double tol)
    {
        CS_ENTRY *x ;
        css *S ;
        csn *N ;
        CS_INT n, ok ;
        if (!CS_CSC (A) || !b) return (0) ;     /* check inputs */
        n = A->n ;
        S = cs_sqr (order, A, 0) ;              /* ordering and symbolic analysis */
        N = cs_lu (A, S, tol) ;                 /* numeric LU factorization */
        x = cs_malloc (n, sizeof (CS_ENTRY)) ;    /* get workspace */
        ok = (S && N && x) ;
        if (ok)
        {
            cs_ipvec (N->pinv, b, x, n) ;       /* x = b(p) */
            cs_lsolve (N->L, x) ;               /* x = L\x */
            cs_usolve (N->U, x) ;               /* x = U\x */
            cs_ipvec (S->q, x, b, n) ;          /* b(q) = x */
        }
        cs_free (x) ;
        cs_sfree (S) ;
        cs_nfree (N) ;
        return (ok) ;
    }