/* Computing formal-algebraic solution to interval linear systems of the form x=Cx+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 *C, *d, *F, *x, *xx; 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; } DIM=2*Dim; ip=calloc(DIM,sizeof(int)); F=calloc(DIM*DIM,sizeof(double)); x=calloc(DIM,sizeof(double)); xx=calloc(DIM,sizeof(double)); C=calloc(Dim*DIM,sizeof(double)); d=calloc(DIM,sizeof(double)); if( ip==NULL || F==NULL || x==NULL || xx==NULL || C==NULL || d==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("\n is improper! \n"); sound(120); delay(800); nosound(); goto final; } *(C+i*DIM+2*j)=u0; *(C+i*DIM+2*j+1)=u1; p=-0.5*(u0+u1); if( i==j ) p+=0.5; if( p>=0. ) { *(F+i*DIM+j)=p; *(F+(i+Dim)*DIM+j+Dim)=p; *(F+(i+Dim)*DIM+j)=0; *(F+i*DIM+j+Dim)=0; } else { *(F+i*DIM+j)=0; *(F+(i+Dim)*DIM+j+Dim)=0; *(F+(i+Dim)*DIM+j)=p; *(F+i*DIM+j+Dim)=p; } } for( i=0; iv1 ) { cprintf("\n\rThe %d-th entry of the right-side vector",i+1); cprintf("\n is improper!\n"); sound(120); delay(800); nosound(); goto final; } *(xx+i)=v0; *(xx+i+Dim)=v1; *(d+2*i)=v0; *(d+2*i+1)=v1; } fclose(fi); /* displaying the input data of the problem */ textcolor(LIGHTGRAY); cprintf("\r\n Dimension of the equation = %u",Dim); cprintf("\r\n The interval matrix C of the equation: \n\n\r"); for( i=0; i0 ) 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; 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; 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); final: textcolor(RED); cprintf("\n\r %50s","Press any key to quit "); getch(); delline(); textcolor(LIGHTGRAY); cprintf("\r %42s","Bye-bye!"); delay(500); delline(); }