private ArrayList covMatrix(ArrayList dataDiff, scattDifference[] firstStep) { Difference[] diffArray = (Difference[])dataDiff.ToArray(typeof(Difference)); double[][] pureMatrix = new double[dataDiff.Count][]; double[][] errorMatrix = new double[dataDiff.Count][]; int i; int j; for (i = 0; i < diffArray.Length; i++) { pureMatrix[i] = new double[i + 1]; errorMatrix[i] = new double[i + 1]; for (j = 0; j <= i; j++) { elMatrix info = new elMatrix(); info = calculateElementMatrix(diffArray[i], diffArray[j], firstStep); pureMatrix[i][j] = info.pureRes; errorMatrix[i][j] = info.errorRes; } } ArrayList matrixFinal = new ArrayList(); matrixFinal.Add(pureMatrix); matrixFinal.Add(errorMatrix); return(matrixFinal); }
private elMatrix calculateElementMatrix(Difference data1, Difference data2, scattDifference[] firstStep) { elMatrix finalResult = new elMatrix(); finalResult.pureRes = 0.0; finalResult.errorRes = 0.0; int i; int k; int c1 = -1; int c2 = -2; if (data1.first > data2.second || data2.first > data1.second) { finalResult.pureRes = 0.0; finalResult.errorRes = 0.0; } else if (data1.first == data2.second || data2.first == data1.second) { finalResult.pureRes = 0.0; finalResult.errorRes = -C.SlopeError * C.SlopeError; } else if (data1.first == data2.first && data1.second == data2.second) { for (i = 0; i < firstStep.Length; i++) { if (firstStep[i].first == data1.first) { c1 = i; } if (firstStep[i].second == data1.second) { c2 = i; } } if (c1 == c2) //vuol dire che lo step è uno solo { finalResult.pureRes = firstStep[c1].value; finalResult.errorRes = 2.0 * C.SlopeError * C.SlopeError; } else //vuol dire che c'è più di 1 cella ed io sommo i sigma delle celle intermedie { for (k = c1; k <= c2; k++) { finalResult.pureRes = finalResult.pureRes + firstStep[k].value; } finalResult.errorRes = 2 * C.SlopeError * C.SlopeError; } } else if (data1.first == data2.first) { c1 = data1.first; c2 = Math.Min(data1.second, data2.second); for (k = c1; k < c2; k++) { finalResult.pureRes = finalResult.pureRes + firstStep[k].value; } finalResult.errorRes = C.SlopeError * C.SlopeError; } else if (data1.second == data2.second) { c1 = Math.Max(data1.first, data1.first); c2 = data1.second; for (k = c1; k < c2; k++) { finalResult.pureRes = finalResult.pureRes + firstStep[k].value; } finalResult.errorRes = C.SlopeError * C.SlopeError; } else { c2 = Math.Min(data1.second, data2.second); c1 = Math.Max(data1.first, data2.first); for (k = c1; k < c2; k++) { finalResult.pureRes = finalResult.pureRes + firstStep[k].value; } finalResult.errorRes = 0; } return(finalResult); }