/* Computing formal-algebraic solution to interval linear systems in Kaucher arithmetic by subdifferential Newton method with a special starting approximation, (c) Sergey Shary, 1995 */ #include #include #include #include #include #include int DIM, *ip; double *C, *d, *F, *x, *xx; char solver() /* solving the point linear system with the matrix F 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"); goto final; } if( Eps<0 ) { cprintf("\n\r Incorrect relative defect! \n"); 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"); goto final; } for( i=0; i=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; 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; /* 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 algebraic system with the subgradient matrix F */ if( solver() ) goto final; q=0; for( i=0; iEps && ni=IterLim ) { cprintf("\r Doesn't the method diverge?! \n"); cprintf("\r The number of iterations alloted is exhausted!\n"); } cprintf("\r Formal-algebraic solution of the equation: \n"); for( i=0; i"); 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(); }