示例#1
0
 static public smat operator *(double value, smat obj)
 {
     smat result = new smat(obj);
     result.reLine();
     while (result.it.line != null)
     {
         while (result.it.row != null)
         {
             result.times(result.it.line.lineId, result.it.row.rowId, value);
             result.it.nextRow();
         }
         result.it.nextLine();
     }
     return result;
 }
示例#2
0
 public double det()
 {
     smat result = tri();
     int i = 0;
     double sum = 1;
     result.reLine();
     while (result.it.line != null)
     {
         if (result.it.row.rowId != i)
             return 0;
         i++;
         sum *= result.it.row.value;
         result.it.nextLine();
     }
     return sum;
 }
示例#3
0
 public smat re()
 {
     smat tmp = new smat(this);
     smat tmp2 = new smat(lineCount);
     smat resultTmp = new smat(lineCount);
     smat result = new smat(lineCount);
     for (int l = 0; l < lineCount; l++)
         resultTmp.set(l, l, 1);
     tmp.reLine();
     resultTmp.reLine();
     lineNode maxline = null;
     lineNode max2line = null;
     lineNode premaxline = null;
     lineNode premax2line = null;
     lineNode resMaxline = null;
     lineNode resMax2line = null;
     lineNode preresMaxline = null;
     lineNode preresMax2line = null;
     int i = 0;
     while (tmp.it.line != null)
     {
         while (tmp.it.line != null)
         {
             if (maxline == null || tmp.it.row.rowId < maxline.firstRow.nextRow.rowId)
             {
                 max2line = maxline;
                 premax2line = premaxline;
                 resMax2line = resMaxline;
                 preresMax2line = preresMaxline;
                 maxline = tmp.it.line;
                 premaxline = tmp.it.preline;
                 resMaxline = resultTmp.it.line;
                 preresMaxline = resultTmp.it.preline;
             }
             else if ((max2line == null || tmp.it.row.rowId < max2line.firstRow.nextRow.rowId) && tmp.it.line.lineId != maxline.lineId)
             {
                 max2line = tmp.it.line;
                 premax2line = tmp.it.preline;
                 resMax2line = resultTmp.it.line;
                 preresMax2line = resultTmp.it.preline;
             }
             tmp.it.nextLine();
             resultTmp.it.nextLine();
         }
         if (max2line != null && maxline.firstRow.nextRow.rowId == max2line.firstRow.nextRow.rowId)
         {
             double basis = max2line.firstRow.nextRow.value / maxline.firstRow.nextRow.value;
             rowNode rowit = maxline.firstRow.nextRow;
             rowNode resRowit = resMaxline.firstRow.nextRow;
             while (rowit != null)
             {
                 add(max2line.lineId, rowit.rowId, -(rowit.value * basis));
                 add(resMax2line.lineId, resRowit.rowId, -(resRowit.value * basis));
                 rowit = rowit.nextRow;
                 resRowit = resRowit.nextRow;
             }
         }
         else
         {
             premaxline.nextLine = maxline.nextLine;
             preresMaxline.nextLine = resMaxline.nextLine;
             maxline.nextLine = null;
             resMaxline.nextLine = null;
             if (premax2line == maxline)
             {
                 premax2line = premaxline;
                 preresMax2line = preresMaxline;
             }
             rowNode j = maxline.firstRow.nextRow;
             rowNode k = resMaxline.firstRow.nextRow;
             while (j != null)
             {
                 tmp2.set(i, j.rowId, j.value/ maxline.firstRow.nextRow.value);
                 j = j.nextRow;
             }
             while (k != null)
             {
                 result.set(i, k.rowId, k.value/ maxline.firstRow.nextRow.value);
                 k = k.nextRow;
             }
             i++;
             tmp2.it.nextLine();
             result.it.nextLine();
             maxline = null;
             resMaxline = null;
             premaxline = null;
             preresMaxline = null;
             max2line = null;
             resMax2line = null;
             premax2line = null;
             preresMax2line = null;
         }
         tmp.reLine();
         resultTmp.reLine();
     }
     if (i != lineCount)
         return new smat(0);
     tmp2.reLine();
     result.reLine();
     for (int l = lineCount - 1; l >= 0; l--)
         for (int j = lineCount - 1; j > l; j--)
         {
             for(int k=j;k<lineCount;k++)
                 result.add(l, k, -result.get(j, k) * tmp2.get(l, j));
             tmp2.it.reRow();
         }
     return result;
 }
示例#4
0
 public smat tri()
 {
     smat tmp = new smat(this);
     smat result = new smat(lineCount);
     lineNode maxline = null;
     lineNode max2line = null;
     lineNode premaxline = null;
     lineNode premax2line = null;
     tmp.reLine();
     int i = 0;
     while (tmp.it.line!= null)
     {
         while (tmp.it.line!= null)
         {
             if (maxline == null || tmp.it.row.rowId < maxline.firstRow.nextRow.rowId)
             {
                 max2line = maxline;
                 premax2line = premaxline;
                 maxline = tmp.it.line;
                 premaxline = tmp.it.preline;
             }
             else if ((max2line == null || tmp.it.row.rowId < max2line.firstRow.nextRow.rowId) && tmp.it.line.lineId != maxline.lineId)
             {
                 max2line = tmp.it.line;
                 premax2line = tmp.it.preline;
             }
             tmp.it.nextLine();
         }
         if (max2line!=null&&maxline.firstRow.nextRow.rowId == max2line.firstRow.nextRow.rowId)
         {
             double basis = max2line.firstRow.nextRow.value / maxline.firstRow.nextRow.value;
             rowNode rowit = maxline.firstRow.nextRow;
             while (rowit != null)
             {
                 tmp.add(max2line.lineId, rowit.rowId, -(rowit.value * basis));
                 rowit = rowit.nextRow;
             }
         }
         else
         {
             premaxline.nextLine = maxline.nextLine;
             maxline.nextLine = null;
             if (premax2line == maxline)
                 premax2line = premaxline;
             rowNode j = maxline.firstRow.nextRow;
             while(j!=null)
             {
                 result.set(i, j.rowId, j.value);
                 j = j.nextRow;
             }
             i++;
             result.it.nextLine();
             maxline = null;
             premaxline = null;
             max2line = null;
             premax2line = null;
         }
         tmp.reLine();
     }
     return result;
 }