#include <stdio.h> #include <math.h> #define mp 3 struct {int ix,iy,itab[128];} ran; int rseed(int ix,int iy); double rndmf(); double gaussj(double a[][mp], int n,double b[]); void main(void) {int i,j,k,n=3,ix=57,iy=89; double a[3][3],at[3][3],as[3][3],b[3]; rseed(ix,iy); for (i=0;i<3;++i){ for (j=0;j<3;++j){ a[i][j]=rndmf()*10;}} for (j=0;j<3;++j){ a[j][j]=1;} for (i=0;i<3;++i){ for (j=0;j<3;++j){ as[i][j]=a[i][j];}} for (j=0;j<3;j++){ printf(" col %d %6f %6f %6f \n",j, as[0][j],as[1][j],as[2][j]);} gaussj(a,n,b); for(i=0;i<3;i++){ for (j=0;j<3;j++){ at[j][i]=0; for(k=0;k<3;k++){ at[j][i]+=as[i][k]*a[k][j];}}} printf(" unit matrix? \n"); for (i=0;i<3;i++) {for (j=0;j<3;j++)printf(" %d %d %6f ",j,i,a[j][i]); printf("\n");} for (i=0;i<3;i++) {for (j=0;j<3;j++)printf(" %d %d %6f ",j,i,at[j][i]); printf("\n");} } double gaussj(double a[][mp], int n,double b[]) {int i,j,k,l,ll,irow,icol,ipiv[mp],indxr[mp],indxc[mp]; double big,temp,pivinv; for(i=0;i= big) {big=fabs(a[j][k]); irow=j; icol=k; } else {if(ipiv[k]>1) {printf(" error 1 /n"); scanf(" %lf",temp); return 1; }
} } /* endif of if then else */ } /* 12 continue */ } /* endif of ipiv(j).ne.1 */ } /* 13 continue */ ipiv[icol]+=1;/* do 13 above */ if(irow!=icol) {for (l=0;l
Related Documents