/* * Solve set of linear equations involving * a Hilbert matrix * i.e. solves Hx=b, where b is the vector [1,1,1....1] * */ #include #include "miracl.h" static flash AA[50][50]; static flash bb[50]; BOOL gauss(flash A[][50],flash b[],int n) { /* solve Ax=b using Gaussian elimination * * solution x returned in b */ int i,j,k,m; BOOL ok; flash w,s; w=mirvar(0); s=mirvar(0); ok=TRUE; for (i=0;i0) m=j; } if (m!=i) for (k=i;k<=n;k++) { copy(A[i][k],w); copy(A[m][k],A[i][k]); copy(w,A[m][k]); } if (size(A[i][i])==0) { ok=FALSE; break; } for (j=i+1;j=i;k--) { fmul(s,A[i][k],w); fsub(A[j][k],w,A[j][k]); } } } if (ok) for (j=n-1;j>=0;j--) { /* Backward substitution */ zero(s); for (k=j+1;k49); for (i=0;i