/* Computing formal-algebraic solution to interval linear systems in Kaucher arithmetic by single-step stationary iterative method with modified real splitting of the matrix, (c) Sergey P. Shary, 1995 */ #include #include #include #include #include #include main(int argc, char *argv[]) { char DataFile[64], *Z; int ier, *ip, i, j, k, m, ni, Dim, DIM; double g0, g1, h0, h1, p, q, s0, s1, t0, t1, u0, u1, v0, v1, Eps, Tau; double *G, *d, *H, *x, *xx; FILE *fi, *fopen(); long IterLim; textmode(C80); clrscr(); textcolor(RED); cprintf("\r\n\n *** "); textcolor(LIGHTRED); cprintf(" Computing formal solutions to interval linear systems "); textcolor(RED); cprintf(" *** \r\n ** "); textcolor(LIGHTRED); cprintf(" by iterative method with real splitting, (c) S.Shary, 1995 "); textcolor(RED); cprintf(" ** \n"); delay(1200); textcolor(LIGHTGRAY); if(argc == 1) { cprintf("\n\rProgram RE_SPLIT computes formal solutions to interval"); cprintf(" linear systems in\n"); cprintf("\r Kaucher arithmetic and implements stationary one-step"); cprintf(" iterative method based\n"); cprintf("\r on modified real splitting of the matrix of the system,"); cprintf(" which is supposed\n"); cprintf("\r to be square. \n\n"); cprintf("\rUsage:"); textcolor(WHITE); cprintf(" RE_SPLIT DataFile \n\n "); textcolor(LIGHTGRAY); cprintf("\rIn the DataFile, the following parameters must occupy the"); cprintf(" first four positions (in order): \n"); textcolor(WHITE); cprintf("\r %15s"," * "); textcolor(LIGHTGRAY); cprintf("dimension of the interval equation (a positive integer), \n"); textcolor(WHITE); cprintf("\r %15s"," * "); textcolor(LIGHTGRAY); cprintf("relative defect of the approximate solution (a positive real),\n"); textcolor(WHITE); cprintf("\r %15s"," * "); textcolor(LIGHTGRAY); cprintf("an auxiliary real parameter (may be arbitrary),\n"); textcolor(WHITE); cprintf("\r %15s"," * "); textcolor(LIGHTGRAY); cprintf("restriction to the number of iterations (a positive integer). \n\n"); cprintf("\rNext the interval matrix (along the rows) and"); cprintf(" right-hand side vector are written out in the DataFile.\n"); goto final; } else strcpy(DataFile,argv[1]); /* reading input data, forming the "middle" matrix G for the given system */ fi=fopen(DataFile,"r"); if( fi==NULL ) { printf("\n\r Error reading the data file %10s ! \n",DataFile); sound(120); delay(1000); nosound(); goto final; } if( fscanf(fi,"%d %lf %lf %lu",&Dim,&Eps,&Tau,&IterLim)<4 ) { cprintf("\n\r Error reading parameters of the algorithm! \n"); sound(120); delay(800); nosound(); goto final; } if( Dim<1 ) { cprintf("\n\r Incorrect dimension of the system! \n"); sound(120); delay(800); nosound(); goto final; } if( Eps<0 ) { cprintf("\n\r Incorrect defect of the solution! \n"); sound(120); delay(800); nosound(); goto final; } DIM=2*Dim; ip=calloc(DIM,sizeof(int)); G=calloc(DIM*DIM,sizeof(double)); x=calloc(DIM,sizeof(double)); xx=calloc(DIM,sizeof(double)); H=calloc(Dim*DIM,sizeof(double)); Z=calloc(Dim*DIM,sizeof(char)); d=calloc(DIM,sizeof(double)); if( ip==NULL||G==NULL||x==NULL||xx==NULL||H==NULL||Z==NULL||d==NULL ) { cprintf("\n\r Not enough room to allocate the data! \n"); sound(120); delay(1000); nosound(); goto final; } for( i=0; i=0. ) { *(G+i*DIM+j)=p; *(G+(i+Dim)*DIM+j+Dim)=p; *(G+(i+Dim)*DIM+j)=0; *(G+i*DIM+j+Dim)=0; } else { *(G+i*DIM+j)=0; *(G+(i+Dim)*DIM+j+Dim)=0; *(G+(i+Dim)*DIM+j)=p; *(G+i*DIM+j+Dim)=p; } } for( i=0; i=0 && u1>=0 ) p=(u0>u1)? u0:u1; *(H+DIM*i+2*j)=u0-p; *(H+DIM*i+2*j+1)=u1-p; *(Z+DIM*i+2*j+1)=(p==0)? 0:1; if( p>=0. ) { *(G+i*DIM+j)=p; *(G+(i+Dim)*DIM+j+Dim)=p; *(G+(i+Dim)*DIM+j)=0; *(G+i*DIM+j+Dim)=0; } else { *(G+i*DIM+j)=0; *(G+(i+Dim)*DIM+j+Dim)=0; *(G+(i+Dim)*DIM+j)=p; *(G+i*DIM+j+Dim)=p; } } /* finding triangular decomposition of the splitted matrix G */ ier=0; *(ip+DIM-1)=1; for( k=0; k=0 && h1>=0 ) m=1; if( h0<=0 && h1>=0 ) m=2; if( h0<=0 && h1<=0 ) m=3; if( h0>=0 && h1<=0 ) m=4; switch ( *(Z+DIM*i+2*j)*4+m ) { case 1: t0=g0*h1; t1=g1*h1; break; case 2: p=g0*h1; q=g1*h0; t0=(pq)?p:q; break; case 3: t0=g1*h0; t1=g0*h0; break; case 4: t0=0; t1=0; break; case 5: t0=g0*h0; t1=g1*h0; break; case 6: t0=0; t1=0; break; case 7: t0=g1*h1; t1=g0*h1; break; case 8: p=g0*h0; q=g1*h1; t0=(p>q)?p:q; p=g0*h1; q=g1*h0; t1=(pEps && ni"); else cprintf(" <-"); } cprintf("\n\n\r Number of iterations = %d",ni); cprintf("\n\r 1-norm of the defect of the approximate solution = %.3E\n",p); final: textcolor(RED); cprintf("\n\r %48s","Press a key to exit "); getch(); delline(); textcolor(LIGHTGRAY); cprintf("\r %40s","Bye-bye!"); delay(500); delline(); }