bingoyes' tiny dream

Gauss Elimination

bool Gauss(){
    int now=1,nxt;
    double t;
    R(i,1,n){
    //enumerate the column
        for(nxt=now;nxt<=n;++nxt)
            if(fabs(a[nxt][i])>eps)break;
    //find a nonzero element in the ith row as 'nxt'
        if(now!=nxt)
            R(j,1,n+1)
                swap(a[nxt][j],a[now][j]);
    //exchange the two lines
        t=a[now][i];
        R(j,1,n+1)
            a[now][j]/=t;
        R(j,1,n)
            if(j!=now){
                t=a[j][i];
                R(k,1,n+1)
                    a[j][k]-=t*a[now][k];
            }
        //elimination each row
        ++now;
        //this column is not useless, goto the next one.
    }
    R(i,now,n)
        if(fabs(a[i][n+1])>eps)
            return 0;
    return 1;
}
上一篇:darkflow测试和训练yolo


下一篇:DIY具有血氧仪和心律检测功能的健身追踪器智能手表