/* Computing formal-algebraic solution to interval linear systems of the form Gx=(G-A)x+b in Kaucher arithmetic by subddifferential Newton method with a special starting approximation, (c) Sergey Shary, 1996 */ #include #include #include #include #include #include int DIM, *ip; double *G, *H, *b, *F, *x, *xx; /* Global variables: DIM - double dimension of the original problem, which is actually the dimension of the auxiliary point equation to be solved in the embedded Euclidean space. ip - auxiliary integer array that is necessary for Gaussian Gaussian elimination in the function "solver". It keeps information about column permutations. G - pointer to the storage area where the point diagonal matrix splitted from A is allocated H - pointer to the storage area where the interval matrix (G-A) is allocated b - pointer to the storage area where the right-hand side interval vector is allocated F - pointer to the storage area where the auxiliary matrix of the double size is allocated. During the iteration of the subdifferential Newton method, F is equal to the the subgradient of the iterated function (in the embedded double dimension space) */ char solver() /* solving a point linear system of the double dimension by Gaussian elimination */ { int ier, i, j, k, m; double p, q; ier=0; *(ip+DIM-1)=1; for( k=0; k1 ) { cprintf("\n\r Incorrect damping factor! \n"); sound(120); delay(800); nosound(); goto final; } if( Eps<0 ) { cprintf("\n\r Incorrect relative defect! \n"); sound(120); delay(800); nosound(); goto final; } /* allotting the storage areas for input data */ DIM=2*Dim; ip=calloc(DIM,sizeof(int)); F=calloc(DIM*DIM,sizeof(double)); x=calloc(DIM,sizeof(double)); xx=calloc(DIM,sizeof(double)); G=calloc(Dim,sizeof(double)); H=calloc(Dim*DIM,sizeof(double)); b=calloc(DIM,sizeof(double)); if( ip==NULL||F==NULL||x==NULL||xx==NULL||G==NULL||H==NULL||b==NULL ) { cprintf("\n\r Not enough room to allocate the data! \n"); sound(120); delay(1000); nosound(); goto final; } for( i=0; iu1 ) { cprintf("\n\rThe entry (%d,%d) of the interval matrix",i+1,j+1); cprintf(" is improper! \n"); sound(120); delay(800); nosound(); goto final; } *(H+i*Dim+j)=u0; *(H+(i+Dim)*Dim+j)=u1; } for( i=0; iv1 ) { cprintf("\n\rThe %d-th entry of the right-side vector",i+1); cprintf(" is improper!\n"); sound(120); delay(800); nosound(); goto final; } *(b+i)=v0; *(b+i+Dim)=v1; *(xx+i)=0; *(xx+i+Dim)=0; } fclose(fi); /* displaying the input data of the problem, forming the additives G and H */ textcolor(LIGHTGRAY); cprintf("\r\n Dimension of the equation = %u",Dim); cprintf("\r\n The interval matrix A of the equation: \n\n\r"); for( i=0; i fabs(q))? p:q; *(G+i)=r; *(H+i*Dim+i)=r-q; *(H+(i+Dim)*Dim+i)=r-p; } else { *(H+i*Dim+j)=-q; *(H+(i+Dim)*Dim+j)=-p; } } cprintf("\n\r"); } cprintf("\n The interval right-hand side vector b: \n\n\r"); for( i=0; i=0. ) { *(F+i*DIM+i)+=p; *(F+(i+Dim)*DIM+i+Dim)+=p; s0=*(x+i)*p; s1=*(x+i+Dim)*p; } else { *(F+(i+Dim)*DIM+i)+=p; *(F+i*DIM+i+Dim)+=p; s0=*(x+i+Dim)*p; s1=*(x+i)*p; } for( j=0; j0 ) l= (g0>0)? 0:2; else l= (g0<=g1)? 1:3; if ( h0*h1>0 ) m= (h0>0)? 1:3; else m= (h0<=h1)? 2:4; /* computing multiplication in Kaucher arithmetic, forming the subgradient matrix F */ switch ( 4*l+m ) { case 1: t0=g0*h0; t1=g1*h1; *(F+i*DIM+j)-=g0; *(F+(i+Dim)*DIM+j+Dim)-=g1; break; case 2: t0=g1*h0; t1=g1*h1; *(F+i*DIM+j)-=g1; *(F+(i+Dim)*DIM+j+Dim)-=g1; break; case 3: t0=g1*h0; t1=g0*h1; *(F+i*DIM+j)-=g1; *(F+(i+Dim)*DIM+j+Dim)-=g0; break; case 4: t0=g0*h0; t1=g0*h1; *(F+i*DIM+j)-=g0; *(F+(i+Dim)*DIM+j+Dim)-=g0; break; case 5: t0=g0*h1; t1=g1*h1; *(F+i*DIM+j+Dim)-=g0; *(F+(i+Dim)*DIM+j+Dim)-=g1; break; case 6: u0=g0*h1; v0=g1*h0; u1=g0*h0; v1=g1*h1; if ( u0v1 ) { t1=u1; *(F+(i+Dim)*DIM+j)-=g0; } else { t1=v1; *(F+(i+Dim)*DIM+j+Dim)-=g1; } break; case 7: t0=g1*h0; t1=g0*h0; *(F+i*DIM+j)-=g1; *(F+(i+Dim)*DIM+j)-=g0; break; case 8: t0=0; t1=0; break; case 9: t0=g0*h1; t1=g1*h0; *(F+i*DIM+j+Dim)-=g0; *(F+(i+Dim)*DIM+j)-=g1; break; case 10: t0=g0*h1; t1=g0*h0; *(F+i*DIM+j+Dim)-=g0; *(F+(i+Dim)*DIM+j)-=g0; break; case 11: t0=g1*h1; t1=g0*h0; *(F+i*DIM+j+Dim)-=g1; *(F+(i+Dim)*DIM+j)-=g0; break; case 12: t0=g1*h1; t1=g1*h0; *(F+i*DIM+j+Dim)-=g1; *(F+(i+Dim)*DIM+j)-=g1; break; case 13: t0=g0*h0; t1=g1*h0; *(F+i*DIM+j)-=g0; *(F+(i+Dim)*DIM+j)-=g1; break; case 14: t0=0; t1=0; break; case 15: t0=g1*h1; t1=g0*h1; *(F+i*DIM+j+Dim)-=g1; *(F+(i+Dim)*DIM+j+Dim)-=g0; break; case 16: u0=g0*h0; v0=g1*h1; u1=g0*h1; v1=g1*h0; if (u0>v0) { t0=u0; *(F+i*DIM+j)-=g0; } else { t0=v0; *(F+i*DIM+j+Dim)-=g1; } if (u1t1)? t0:t1; } /* solving the point linear system with the subgradient matrix F */ if( solver() ) goto final; /* computing the next approximation to the solution and its 1-norm */ q=0; for( i=0; iEps && 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",r); /* farewell */ final: textcolor(RED); cprintf("\n\r %50s","Press any key to quit "); getch(); delline(); textcolor(LIGHTGRAY); cprintf("\r %42s","Bye-bye!"); delay(500); delline(); }