private void Initialization(decimal[,] matrixParam, decimal[] vectorParam) { systemSize = vectorParam.Length; primaryMatrix = new decimal[systemSize, systemSize]; yVector = new decimal[systemSize]; Array.Copy(matrixParam, primaryMatrix, matrixParam.Length); Array.Copy(vectorParam, yVector, vectorParam.Length); }
/// <summary> /// Calculates the ROE from given inputs. /// </summary> /// <param name="revenue"></param> /// <param name="sp"></param> /// <param name="cost"></param> /// <param name="rore"></param> /// <param name="dfCapital"></param> /// <param name="dfMarket"></param> /// <param name="taxRate"></param> /// <param name="frankingRate"></param> /// <param name="regCap"></param> /// <param name="ffp"></param> /// <param name="fxRate"></param> /// <returns></returns> public decimal[,] CalculateROE(decimal[,] revenue, decimal[] sp, decimal[] cost, decimal[] rore, decimal[] dfCapital, decimal[] dfMarket, decimal taxRate, decimal frankingRate, decimal[] regCap, decimal ffp, decimal fxRate) { var result = ROEAnalytics.CalculateROE(ArrayHelper.MatrixToArray(revenue), sp, cost, rore, dfCapital, dfMarket, taxRate, frankingRate, regCap, ffp, fxRate); return(ArrayHelper.ArrayToVerticalMatrix(result)); }
public static void Main() { // https://www.youtube.com/watch?v=gSGf8P8D_uY decimal[,] costArray = FindMinimumCost(FirstString, SecondString); Console.WriteLine("The minimal sum of costs: {0}", costArray[FirstString.Length, SecondString.Length]); PrintArr(costArray); }
public static decimal[,] Copy(this decimal[,] arr) { int uBound0 = arr.GetUpperBound(0); int uBound1 = arr.GetUpperBound(1); decimal[,] newArr = new decimal[uBound0, uBound1]; arr.CopyTo(newArr, 0); return(newArr); }
static void swaprow(decimal[,] inputs, int pivot, int i, int input) { for (int j = 0; j <= input; j++) { decimal temp = inputs[i, j]; inputs[i, j] = inputs[pivot, j]; inputs[pivot, j] = temp; } }
public void Rotate(Vector3 angles) { decimal[,] rotationMatrix = MatrixMath.GetRotationMatrix(angles.Y, angles.X, angles.Z); decimal x = X, y = Y, z = Z; X = x * rotationMatrix[0, 0] + y * rotationMatrix[0, 1] + z * rotationMatrix[0, 2]; Y = x * rotationMatrix[1, 0] + y * rotationMatrix[1, 1] + z * rotationMatrix[1, 2]; Z = x * rotationMatrix[2, 0] + y * rotationMatrix[2, 1] + z * rotationMatrix[2, 2]; }
static void rowdiv(decimal[,] a, int r, decimal s) { int co = a.GetLength(1); for (int q = 0; q < co; q++) { a[r, q] = a[r, q] / s; } }
static void convertUnit(decimal[,] inputs, int i, int k, int input) { decimal temp = inputs[i, k]; for (int j = 0; j <= input; j++) { inputs[i, j] = inputs[i, j] / temp; } }
/// <summary> /// 向量对角化 /// </summary> /// <param name="vec">向量</param> /// <returns>返回对角化矩阵</returns> public static decimal[,] VecDiag(this decimal[,] vec) { decimal[,] diagMatrix = new decimal[vec.GetLength(0), vec.GetLength(0)]; for (int i = 0, len = vec.GetLength(0); i < len; i++) { diagMatrix[i, i] = vec[i, 0]; } return(diagMatrix); }
public Scoreboard(int numberOfTeams, int numberOfCategories) { teams = new string[numberOfTeams]; categories = new string[numberOfCategories]; scores = new decimal[numberOfTeams, numberOfCategories]; currentTeam = 0; currentCategory = 0; }
// На вход получаем матрицу Гессе, находим для нее обратную матрицу и её определитель public static decimal FindDeterminantOfInverseMatrix(decimal[,] matrix, int size) { var determ = Determinant(matrix, size); var alMatrix = Allied(matrix, size); var InverseMatrix = Multiply(1 / determ, alMatrix, size); var result = Determinant(InverseMatrix, size); return(result); }
/// <summary> /// Делит строку на указанный коэффициент /// </summary> static void DivideString(decimal[,] matrix, int index, decimal koeff = 1) { var length = matrix.GetLength(1); for (var i = 0; i < length; i++) { matrix[index, i] /= koeff; } }
static void rowsub(decimal[,] a, int i, int j, decimal s) { int co = a.GetLength(1); for (int q = 0; q < co; q++) { a[i, q] = a[i, q] - (s * a[j, q]); } }
/// <summary> /// Calculates the ROE from given inputs. /// </summary> /// <param name="revenue"></param> /// <param name="sp"></param> /// <param name="cost"></param> /// <param name="rorc"></param> /// <param name="dfCapital"></param> /// <param name="taxRate"></param> /// <param name="frankingRate"></param> /// <param name="riskCap"></param> /// <param name="ffp"></param> /// <param name="fxRate"></param> /// <returns></returns> public decimal[,] CalculateRAROC(decimal[,] revenue, decimal[,] sp, decimal[,] cost, decimal[,] rorc, decimal[,] dfCapital, decimal taxRate, decimal frankingRate, decimal[,] riskCap, decimal ffp, decimal fxRate) { var result = RAROCAnalytics.CalculateRAROC(ArrayHelper.MatrixToArray(revenue), ArrayHelper.MatrixToArray(sp), ArrayHelper.MatrixToArray(cost), ArrayHelper.MatrixToArray(rorc), ArrayHelper.MatrixToArray(dfCapital), taxRate, frankingRate, ArrayHelper.MatrixToArray(riskCap), ffp, fxRate); return(ArrayHelper.ArrayToVerticalMatrix(result)); }
public MatrixDecimal() { _decimalArray = new decimal[1, 1]; _decimalArray[0, 0] = 0; _n = 1; _m = 1; _codeError = 0; _num_m++; }
/// <summary> /// This method finds the next smallest value in the array, after the value found in the index specified. If the same /// value exists multiple times, the lower index is returned. /// </summary> /// <param name="distances">The pre-calculated distance matrix.</param> /// <param name="indexLast"></param> /// <returns>The next smallest distance index from the last indexes.</returns> public static int[] NextSmallestDistanceIndex(decimal[,] distances, int[] indexLast) { if (ParameterValidation.IsDecimalArrayNullOrEmpty(distances)) { throw new ArgumentOutOfRangeException(nameof(distances)); } if (ParameterValidation.IsIntArrayNullOrEmpty(indexLast)) { throw new ArgumentOutOfRangeException(nameof(indexLast)); } var indexBest = new[] { -1, -1 }; //var indexBestA = -1; //var indexBestB = -1; if ((indexLast[0] == -1) || (indexLast[1] == -1)) { return(FirstSmallestDistanceIndex(distances)); } for (int indexA = distances.GetLowerBound(0); indexA <= distances.GetUpperBound(0); indexA++) { for (int indexB = distances.GetLowerBound(1); indexB <= distances.GetUpperBound(1); indexB++) { if //// Not the same object twice / no distance measurement ... zero. ((indexA != indexB) && //// Not the same indexes the other way around as last time (at least one value changed). (indexLast[0] != indexB || indexLast[1] != indexA) && //// Not the same indexes the same way around as last time (at least one value changed). (indexLast[0] != indexA || indexLast[1] != indexB) && //// Distance can be the same as the last one - if the index is higher. ((Math.Abs(distances[indexA, indexB]) == Math.Abs(distances[indexLast[0], indexLast[1]]) && (indexA > indexLast[0] || (indexA >= indexLast[0] && indexB > indexLast[1]))) || //// Distance can be more, but only if it is less than the best found so far. (Math.Abs(distances[indexA, indexB]) > Math.Abs(distances[indexLast[0], indexLast[1]]) && (indexBest[0] == -1 || indexBest[1] == -1 || Math.Abs(distances[indexA, indexB]) < Math.Abs(distances[indexBest[0], indexBest[1]]))))) { indexBest[0] = indexA; indexBest[1] = indexB; if (distances[indexA, indexB] == distances[indexLast[0], indexLast[1]]) { // If the distance is the same, then it is impossible to find a lower one, so break out, also, if no break, indexes may be skipped. break; } } } } return(indexBest); //new int[] { indexBestA, indexBestB }; }
public void TestUpgma() { //decimal[,] distanceMatrix1 = //{ // { 0, 0, 0, 0, 0 }, // { 0, 0, 1, 1, 1 }, // { 0, 1, 0, 2, 2 }, // { 0, 1, 2, 0, 3 }, // { 0, 1, 2, 3, 0 }, //}; //var result = UpgmaClustering.Upgma(distanceMatrix1); decimal[,] distanceMatrix2 = { { 0, 19, 27, 8, 33, 18, 13 }, { 19, 0, 31, 18, 36, 1, 13 }, { 27, 31, 0, 26, 41, 32, 29 }, { 8, 18, 26, 0, 31, 17, 14 }, { 33, 36, 41, 31, 0, 35, 28 }, { 18, 1, 32, 17, 35, 0, 12 }, { 13, 13, 29, 14, 28, 12, 0 } }; var names = new List <string>(); for (var i = 0; i < distanceMatrix2.GetLength(0); i++) { names.Add("" + i); } List <string> vectorNames = new List <string>(); var maxVectorLength = distanceMatrix2.GetLength(0) > distanceMatrix2.GetLength(1) ? distanceMatrix2.GetLength(0) : distanceMatrix2.GetLength(1); for (var i = 0; i < maxVectorLength; i++) { vectorNames.Add(SpreadsheetFileHandler.AlphabetLetterRollOver(i) + i); } List <List <UpgmaNode> > nodeList; List <List <string> > treeList; var minimumOutputTreeLeafs = 1; List <string> finalTreeLeafOrderList; UpgmaClustering.Upgma(distanceMatrix2, vectorNames, minimumOutputTreeLeafs, out nodeList, out treeList, out finalTreeLeafOrderList); CheckUpgmaDistanceConsistency(nodeList[nodeList.Count - 1]); List <string> treeLeafOrderList; var tree = Newick.NewickTreeFormat(nodeList[nodeList.Count - 1].ToList <GenericNode>(), names, out treeLeafOrderList, minimumOutputTreeLeafs); Console.WriteLine(tree); }
private decimal GetRushOrderCost(decimal surfaceArea) { decimal[,] rushOrderPrices = _quoteFileManager.GetRushOrderPrices(); if (surfaceArea < 1000) { switch (RushOrderType) { case RushOrderType.ThreeDay: return(rushOrderPrices[0, 0]); case RushOrderType.FiveDay: return(rushOrderPrices[0, 1]); case RushOrderType.SevenDay: return(rushOrderPrices[0, 2]); default: return(0); } } else if (surfaceArea >= 1000 && surfaceArea <= 2000) { switch (RushOrderType) { case RushOrderType.ThreeDay: return(rushOrderPrices[1, 0]); case RushOrderType.FiveDay: return(rushOrderPrices[1, 1]); case RushOrderType.SevenDay: return(rushOrderPrices[1, 2]); default: return(0); } } else { switch (RushOrderType) { case RushOrderType.ThreeDay: return(rushOrderPrices[2, 0]); case RushOrderType.FiveDay: return(rushOrderPrices[2, 1]); case RushOrderType.SevenDay: return(rushOrderPrices[2, 2]); default: return(0); } } }
static decimal MainDiagonalSum(decimal[,] array) { decimal sum = 0; for (int i = 0; i < array.GetLength(0); i++) { sum += array[i, i]; } return(sum); }
public Matrix(decimal[] vector) { row = 1; column = vector.GetUpperBound(0) + 1; data = new decimal[1, column]; for (int i = 0; i < vector.Length; i++) { data[0, i] = vector[i]; } }
/// <summary> /// Devuelve la suma de los cargos o abonos del arreglo introducido /// </summary> /// <param name="Cuenta"></param> /// <returns></returns> public decimal sumaCuenta(decimal[,] Cuenta) { decimal suma = 0; for (int i = 0; i < Cuenta.GetLength(0); i++) { suma += Cuenta[i, 1]; } return(suma); }
static void BiggestNumber(decimal[,] matrix) { decimal sum = 0; for (int i = 0; i < matrix.GetLength(0); i++) { sum += matrix[i, i]; } Console.WriteLine("The sum of the main diagonal is " + sum); }
private static IEnumerable <decimal> GetColumn(decimal[,] matrix, int columnIndex) { //Get a certain column inside the matrix: iterate through all rows with fixed column index var rowCount = matrix.GetLength(0); for (var i = 0; i < rowCount; i++) { yield return(matrix[i, columnIndex]); } }
private static IEnumerable <decimal> GetRow(decimal[,] matrix, int rowIndex) { //Get a certain row inside the matrix: iterate through all columns with fixed row index var columnCount = matrix.GetLength(1); for (var i = 0; i < columnCount; i++) { yield return(matrix[rowIndex, i]); } }
private static Matrix GetTestMatrix() { decimal[,] testArray = { { /*0,0*/ 1m, 2m, 3m, 4m, 5m }, { 6m, 7m, 8m, 9m, 10m }, { 11m, 12m, 13m, 14m, 15m }, { 16m, 17m, 18m, 19m, 20m /*4,3*/ } }; var matrix = new Matrix(testArray); return(matrix); }
static void Main(string[] args) { n = int.Parse(Console.ReadLine()); k = int.Parse(Console.ReadLine()); matrix = new decimal[n + 1, k + 1]; decimal result = CalcBinomCoeff(n, k); Console.WriteLine(result); }
private void ScaleCycle(decimal[,] cycle, decimal scale) { int cycleLength = cycle.Length / 2; for (int i = 0; i < cycleLength; ++i) { cycle[i, 0] *= scale; cycle[i, 1] *= scale; } }
static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); int k = int.Parse(Console.ReadLine()); matrix = new decimal[n * n, n *n]; Console.WriteLine(Binom(n, k)); }
public void LearnMulArray() { // 2D array int[,] numbers = new int [3, 4]; numbers[0, 0] = 2; numbers[2, 3] = 5; decimal[,] numbers2 = { { 2.3m, 34.3m }, { 23.3m, 33.22m } }; }
public static int test_1_store_decimal() { decimal[,] a = { { 1 } }; if (a[0, 0] != 1m) { return(0); } return(1); }
/// <summary>Constructs a QR decomposition.</summary> /// <param name="value">The matrix A to be decomposed.</param> /// <param name="transpose">True if the decomposition should be performed on /// the transpose of A rather than A itself, false otherwise. Default is false.</param> public QrDecompositionD(decimal[,] value, bool transpose) { if (value == null) { throw new ArgumentNullException("value", "Matrix cannot be null."); } if ((!transpose && value.GetLength(0) < value.GetLength(1)) || (transpose && value.GetLength(1) < value.GetLength(0))) { throw new ArgumentException("Matrix has more columns than rows.", "value"); } this.qr = transpose ? value.Transpose() : (decimal[,])value.Clone(); int rows = qr.GetLength(0); int cols = qr.GetLength(1); this.Rdiag = new decimal[cols]; for (int k = 0; k < cols; k++) { // Compute 2-norm of k-th column without under/overflow. decimal nrm = 0; for (int i = k; i < rows; i++) nrm = Tools.Hypotenuse(nrm, qr[i, k]); if (nrm != 0) { // Form k-th Householder vector. if (qr[k, k] < 0) nrm = -nrm; for (int i = k; i < rows; i++) qr[i, k] /= nrm; qr[k, k] += 1; // Apply transformation to remaining columns. for (int j = k + 1; j < cols; j++) { decimal s = 0; for (int i = k; i < rows; i++) s += qr[i, k] * qr[i, j]; s = -s / qr[k, k]; for (int i = k; i < rows; i++) qr[i, j] += s * qr[i, k]; } } this.Rdiag[k] = -nrm; } }
public NuGenMatrix(int rowsCount, int colsCount, decimal[] data) { if (data == null) { throw new System.ArgumentNullException("Cannot create the matrix!"); } int r = data.GetLength(0); int c = data.GetLength(1); decimal[,] dataM = new decimal[r, c]; for (int i = 0; i < r; i++) { for (int j = 0; j < c; j++) { dataM[i, j] = data[i * c + j]; } } Data = dataM; }
private void BuildGrid(int size, int count) { for (int bell = 1; bell < count; bell++) { decimal[,] newGrid = new decimal[size + 1, size + 1]; for (int x = 1; x <= size; x++) { for (int y = 1; y <= size; y++) { if (x < size) { newGrid[x, y] += 1 / _adjacent[x + 1, y] * (_grid[x + 1, y]); } if (x > 1) { newGrid[x, y] += 1 / _adjacent[x - 1, y] * (_grid[x - 1, y]); } if (y < size) { newGrid[x, y] += 1 / _adjacent[x, y + 1] * (_grid[x, y + 1]); } if (y > 1) { newGrid[x, y] += 1 / _adjacent[x, y - 1] * (_grid[x, y - 1]); } } } _grid = newGrid; } }