646{
647 if(ncol != nrow)
648 {
error(
"G4ErrorMatrix::invert: G4ErrorMatrix is not NxN"); }
649
650 static G4int max_array = 20;
652
653 if (ncol > max_array)
654 {
655 delete [] ir;
656 max_array = nrow;
657 ir =
new G4int [max_array+1];
658 }
662 switch(nrow)
663 {
664 case 3:
665 G4double c11,c12,c13,c21,c22,c23,c31,c32,c33;
666 ifail = 0;
667 c11 = (*(m.begin()+4)) * (*(m.begin()+8))
668 - (*(m.begin()+5)) * (*(m.begin()+7));
669 c12 = (*(m.begin()+5)) * (*(m.begin()+6))
670 - (*(m.begin()+3)) * (*(m.begin()+8));
671 c13 = (*(m.begin()+3)) * (*(m.begin()+7))
672 - (*(m.begin()+4)) * (*(m.begin()+6));
673 c21 = (*(m.begin()+7)) * (*(m.begin()+2))
674 - (*(m.begin()+8)) * (*(m.begin()+1));
675 c22 = (*(m.begin()+8)) * (*m.begin())
676 - (*(m.begin()+6)) * (*(m.begin()+2));
677 c23 = (*(m.begin()+6)) * (*(m.begin()+1))
678 - (*(m.begin()+7)) * (*m.begin());
679 c31 = (*(m.begin()+1)) * (*(m.begin()+5))
680 - (*(m.begin()+2)) * (*(m.begin()+4));
681 c32 = (*(m.begin()+2)) * (*(m.begin()+3))
682 - (*m.begin()) * (*(m.begin()+5));
683 c33 = (*m.begin()) * (*(m.begin()+4))
684 - (*(m.begin()+1)) * (*(m.begin()+3));
685 t1 = std::fabs(*m.begin());
686 t2 = std::fabs(*(m.begin()+3));
687 t3 = std::fabs(*(m.begin()+6));
688 if (t1 >= t2)
689 {
690 if (t3 >= t1)
691 {
692 temp = *(m.begin()+6);
693 det = c23*c12-c22*c13;
694 }
695 else
696 {
697 temp = *(m.begin());
698 det = c22*c33-c23*c32;
699 }
700 }
701 else if (t3 >= t2)
702 {
703 temp = *(m.begin()+6);
704 det = c23*c12-c22*c13;
705 }
706 else
707 {
708 temp = *(m.begin()+3);
709 det = c13*c32-c12*c33;
710 }
711 if (det==0)
712 {
713 ierr = 1;
714 return;
715 }
716 {
717 ss = temp/det;
719 *(mq++) = ss*c11;
720 *(mq++) = ss*c21;
721 *(mq++) = ss*c31;
722 *(mq++) = ss*c12;
723 *(mq++) = ss*c22;
724 *(mq++) = ss*c32;
725 *(mq++) = ss*c13;
726 *(mq++) = ss*c23;
727 *(mq) = ss*c33;
728 }
729 break;
730 case 2:
731 ifail = 0;
732 det = (*m.begin())*(*(m.begin()+3)) - (*(m.begin()+1))*(*(m.begin()+2));
733 if (det==0)
734 {
735 ierr = 1;
736 return;
737 }
738 ss = 1.0/det;
739 temp = ss*(*(m.begin()+3));
740 *(m.begin()+1) *= -ss;
741 *(m.begin()+2) *= -ss;
742 *(m.begin()+3) = ss*(*m.begin());
743 *(m.begin()) = temp;
744 break;
745 case 1:
746 ifail = 0;
747 if ((*(m.begin()))==0)
748 {
749 ierr = 1;
750 return;
751 }
752 *(m.begin()) = 1.0/(*(m.begin()));
753 break;
754 case 4:
756 return;
757 case 5:
759 return;
760 case 6:
762 return;
763 default:
764 ifail = dfact_matrix(det, ir);
765 if(ifail) {
766 ierr = 1;
767 return;
768 }
769 dfinv_matrix(ir);
770 break;
771 }
772 ierr = 0;
773 return;
774}
virtual void invertHaywood4(G4int &ierr)
virtual void invertHaywood5(G4int &ierr)
virtual void invertHaywood6(G4int &ierr)