public void ExceptionIncompatibleMatrices() { IMathematicalMatrix matrix1 = new Matrix(2, 3); matrix1[0, 0] = 1; matrix1[0, 1] = 2; matrix1[0, 2] = -4; matrix1[1, 0] = 0; matrix1[1, 1] = 3; matrix1[1, 2] = -1; IMathematicalMatrix matrix2 = MatrixTest.GetTestMatrix(); matrix1.Add(matrix2); }
public void AddMatricesDiffSizeTest1() { var matrix1 = new Matrix(new[] { new Vector(new[] { new Number(6), new Number(3) }), new Vector(new[] { new Number(2), new Number(1) }) }); var matrix2 = new Matrix(new[] { new Vector(new[] { new Number(9), new Number(2) }), new Vector(new[] { new Number(4), new Number(3), new Number(9) }) }); var result = matrix1.Add(matrix2); }
public void AddRaiseExceptionIfDifferentRowSize() { Matrix matrix1 = new Matrix(new double[][] { new double[] { 1.0, 2.0 }, new double[] { 3.0, 4.0 } }); Matrix matrix2 = new Matrix(new double[][] { new double[] { 5.0, 6.0 }, new double[] { 7.0, 8.0 }, new double[] { 9.0, 10.0 } }); try { matrix1.Add(matrix2); Assert.Fail(); } catch (Exception ex) { Assert.IsInstanceOfType(ex, typeof(InvalidOperationException)); Assert.AreEqual("Matrices have different sizes", ex.Message); } }
public void Add() { Matrix matrix1 = new Matrix(new double[][] { new double[] { 1.0, 2.0 }, new double[] { 3.0, 4.0 } }); Matrix matrix2 = new Matrix(new double[][] { new double[] { 5.0, 6.0 }, new double[] { 7.0, 8.0 } }); Matrix matrix = matrix1.Add(matrix2); Assert.AreEqual(4, matrix.Size); var elements = matrix.Elements; Assert.AreEqual(1.0 + 5.0, elements[0][0]); Assert.AreEqual(2.0 + 6.0, elements[0][1]); Assert.AreEqual(3.0 + 7.0, elements[1][0]); Assert.AreEqual(4.0 + 8.0, elements[1][1]); }
public void AddMatricesDiffSizeTest2() { var matrix1 = new Matrix(new[] { new Vector(new[] { new Number(6), new Number(3) }), new Vector(new[] { new Number(2), new Number(1) }) }); var matrix2 = new Matrix(new[] { new Vector(new[] { new Number(9), new Number(2) }), new Vector(new[] { new Number(4), new Number(3) }), new Vector(new[] { new Number(1), new Number(7) }) }); Assert.Throws<ArgumentException>(() => matrix1.Add(matrix2)); }
public void Init() { matrix = new Matrix<double>(); p = new Point<double>(10d, 10d); pos = new Position<double>(); var n = new Random(); for (int i = 0; i < MAX_POSITIONS; i++) { for (int j = 0; j < MAX_POINTS; j++) { pos.Add(new Point<double>(n.NextDouble(), n.NextDouble())); } matrix.Add(pos); } }
public OptionsForm() { InitializeComponent(); try { using (var reader = File.OpenText("math.default")) { var n = 0; var m = new Matrix<decimal>(); var a = new Matrix<decimal>(); var b = new Matrix<decimal>(); var f = new Matrix<decimal>(); var w = new Matrix<decimal>(); for (var line = reader.ReadLine(); !string.IsNullOrWhiteSpace(line); line = reader.ReadLine()) { var arr = line.Split(' '); if (arr[0][0] == 'N') { n = Convert.ToInt32(arr[1]); } else { var x = new Vector<decimal>(); for (var i = 1; i < arr.Length; i++) x.Add(Convert.ToDecimal(arr[i])); if (arr[0][0] == 'M') m.Add(x); if (arr[0][0] == 'A') a = new Matrix<decimal> {x}; if (arr[0][0] == 'B') b = new Matrix<decimal> {x}; if (arr[0][0] == 'F') f.Add(x); if (arr[0][0] == 'W') w.Add(x); } } numericUpDown1.Value = n; _matrixControlM.Value = m; _matrixControlA.Value = a; _matrixControlB.Value = b; _matrixControlF.Value = f; _matrixControlW.Value = w; } } catch (Exception ex) { } }
public void AddMatricesTest() { var matrix1 = new Matrix(new[] { new Vector(new[] { new Number(6), new Number(3) }), new Vector(new[] { new Number(2), new Number(1) }) }); var matrix2 = new Matrix(new[] { new Vector(new[] { new Number(9), new Number(2) }), new Vector(new[] { new Number(4), new Number(3) }) }); var expected = new Matrix(new[] { new Vector(new[] { new Number(15), new Number(5) }), new Vector(new[] { new Number(6), new Number(4) }) }); var result = matrix1.Add(matrix2); Assert.AreEqual(expected, result); }
public long Solve() { var text = File.ReadAllLines(@"..\..\Problems\Problem082.txt"); var matrix = new Matrix(); var lineNumber = 0; var columnNumber = 0; foreach (var line in text) { foreach (var number in line.Split(',')) { matrix.Add(lineNumber, columnNumber, int.Parse(number)); columnNumber++; } lineNumber++; columnNumber = 0; } matrix.MinPath(0, 0); return matrix.GetMinPath(M - 1, M - 1); }
static void Main(string[] args) { Point3D point1 = new Point3D(2,3,4); Point3D point2 = new Point3D(1,1,1); Console.WriteLine(CalculateDistance.calct(point1, point2)); Path collection = new Path(); collection.AddPoint(point1, point2); PathStorage.Save(collection.PathList, "Colection1"); PathStorage.Save(collection.PathList, "Colection2"); Console.WriteLine("Load \"Colection1\""); for (int i = 0; i < PathStorage.Load("Colection1").Count; i++) { Console.WriteLine("Point {0} cordinates: X={1}, Y={2}, Z={3}", i, PathStorage.Load("Colection1")[i].X, PathStorage.Load("Colection1")[i].Y, PathStorage.Load("Colection1")[i].Z); } GenericList<int> LIST = new GenericList<int>(); LIST.Insert(51, 2); LIST.Insert(51, 1); LIST.Insert(51, 3); LIST.Insert(51, 3); LIST.AddElement(111); Console.WriteLine(LIST.Access(8)); Console.WriteLine("ss"+LIST.array.Length + "Golemina na masiva"); Console.WriteLine(LIST.Find(111)); Console.WriteLine(LIST.Min() + " Min"); Console.WriteLine(LIST.Max() + " Max"); LIST.ClearArray(); Console.WriteLine(LIST.Access(4)); Matrix<int> matrix = new Matrix<int>(5,5); matrix.Add(1,1,5); matrix[1, 1] = 5; Console.WriteLine(matrix[1, 1]); }
private static void Main() { // Points Point3D.Z = 12; Console.WriteLine(Point3D.Z); Console.WriteLine(Point3D.PointO); double betweenTwoPoints = StaticClass.DistanceBetweenTwoPoints(); Console.WriteLine(betweenTwoPoints); Path testingPath = new Path(12.32); testingPath.AddPointAndPrintAllPoints(12.12); PathStorage.AddPoints("123 123 123"); PathStorage.ReadPoints(); // Generic list var list = new GenericList<int>(1); // Resizeing Console.WriteLine(list.Length); list.Add(1); list.Add(2); Console.WriteLine(list.Length); list.Add(-2); Console.WriteLine(list.Length); list.Add(2); Console.WriteLine(list.Length); list.Add(122); Console.WriteLine(list.Length); // Max and min var max = list.Max(); Console.WriteLine(max); var min = list.Min(); Console.WriteLine(min); // Removes 3 list.RemoveAt(2); Console.WriteLine(); // Inserting at position list.InsertAt(0, 133); // Printing for (int i = 0; i < list.Length; i++) { Console.WriteLine(list[i]); } // To String Console.WriteLine(); string toString = list.ToString(); Console.WriteLine(toString); // Empty the array Console.WriteLine(); list.Clear(); for (int i = 0; i < list.Length; i++) { Console.WriteLine(list[i]); } list.Add(1); list.Add(2); list.Add(3); // FindingIndex Console.WriteLine(); var find = list.IndexOf(2); Console.WriteLine(find); // Testing the matrix var matrixOne = new Matrix<int>(3, 3); matrixOne.Add(1); matrixOne.Add(1); matrixOne.Add(1); matrixOne.Add(1); var matrixTwo = new Matrix<int>(3, 3); matrixTwo.Add(2); matrixTwo.Add(2); matrixTwo.Add(2); matrixTwo.Add(2); var newMatrix = matrixOne + matrixTwo; for (int row = 0; row < 3; row++) { for (int col = 0; col < 3; col++) { // if you change the 0 to any other number or whatever the if below will return true newMatrix[row, col] = 0; Console.Write(newMatrix[row, col] + " "); } Console.WriteLine(); } if (newMatrix) { Console.WriteLine("The matrix statement is true"); } }
protected double GetSVDRotation(Matrix<double>[] p1, Matrix<double>[] p2, out Matrix<double> rotation) { var centr1 = GetCentroid(p1); var centr2 = GetCentroid(p2); var q1 = new List<Matrix<double>>(); var q2 = new List<Matrix<double>>(); var H = new Matrix<double>(3, 3); for (int i = 0; i < Math.Min(p1.Count(), p2.Count()); ++i) { var q1d = new Matrix<double>(new double[,] { {p1[i][0, 0] - centr1[0, 0]}, {p1[i][1, 0] - centr1[1, 0]}, {p1[i][2, 0] - centr1[2, 0]} }); q1.Add(q1d); var q2d = new Matrix<double>(new double[,] { {p2[i][0, 0] - centr2[0, 0]}, {p2[i][1, 0] - centr2[1, 0]}, {p2[i][2, 0] - centr2[2, 0]} }); q2.Add(q2d); H = H.Add(q1d.Mul(q2d.Transpose())); } var U = new Matrix<double>(3, 3); var W = new Matrix<double>(3, 3); var V = new Matrix<double>(3, 3); CvInvoke.cvSVD(H, W, U, V, SVD_TYPE.CV_SVD_DEFAULT); var X = V.Mul(U.Transpose()); var detX = CvInvoke.cvDet(X); rotation = X; return detX; }
private void button5_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() != DialogResult.OK) return; var fileName = openFileDialog1.FileName; try { using (var reader = File.OpenText(fileName)) { var n = 0; var m = new Matrix<decimal>(); var a = new Matrix<decimal>(); var b = new Matrix<decimal>(); var f = new Matrix<decimal>(); var w = new Matrix<decimal>(); for (var line = reader.ReadLine(); !string.IsNullOrWhiteSpace(line); line = reader.ReadLine()) { var arr = line.Split(' '); if (arr[0][0] == 'N') { n = Convert.ToInt32(arr[1]); } else { var x = new Vector<decimal>(); for (var i = 1; i < arr.Length; i++) x.Add(Convert.ToDecimal(arr[i])); if (arr[0][0] == 'M') m.Add(x); if (arr[0][0] == 'A') a = new Matrix<decimal> {x}; if (arr[0][0] == 'B') b = new Matrix<decimal> {x}; if (arr[0][0] == 'F') f.Add(x); if (arr[0][0] == 'W') w.Add(x); } } numericUpDown1.Value = n; _matrixControlM.Value = m; _matrixControlA.Value = a; _matrixControlB.Value = b; _matrixControlF.Value = f; _matrixControlW.Value = w; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// This method returns the 2 ROIs that are more "aligned", i.e. with the /// lowest difference in the Y coordinate /// It calculates the distances between all the ROIs and selects the appropriate pair /// </summary> /// <param name="ROIs"></param> /// <returns></returns> private MCvAvgComp[] AlignedROIs(MCvAvgComp[] ROIs) { MCvAvgComp[] alignedROIs = new MCvAvgComp[2]; int N = ROIs.Length; Matrix<int> distancesY = new Matrix<int>(N, N); distancesY = distancesY.Add(100000); double minimum; double maximum; Point minimumLocation; Point maximumLocation; for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { // If both rectangles do not intersect, we add their distance to the matrix // MT: Min distance of 2 x roi.width if (ROIs[j].rect.IntersectsWith(ROIs[i].rect) == false && Math.Abs(ROIs[j].rect.X - ROIs[i].rect.X) > ROIs[j].rect.Width*2.5) distancesY[i, j] = Math.Abs(ROIs[j].rect.Y - ROIs[i].rect.Y); } } distancesY.MinMax(out minimum, out maximum, out minimumLocation, out maximumLocation); alignedROIs[0] = ROIs[minimumLocation.X]; alignedROIs[1] = ROIs[minimumLocation.Y]; return alignedROIs; }
/// <summary> /// Build the weighting maps /// </summary> private void BuildForwardWeightingMap() { // All goal weightings staticForwardCrateWeighting = new Matrix(goalMap,55f); // Corner goals get another 10 Bitmap cornerGoals = goalMap.BitwiseAND(cornerMap); staticForwardCrateWeighting = staticForwardCrateWeighting.Add(new Matrix(cornerGoals, 33f)); staticForwardCrateWeighting = staticForwardCrateWeighting.Average(boundryMap); // No crates will ever get onto a dead piece, but this will make the area around a dead cell less likely to be filled by crates staticForwardCrateWeighting = staticForwardCrateWeighting.Add(new Matrix(deadMap, -5f)); // Player map staticPlayerRating = new Matrix(controller.Map.Size); // Leave the plaer map at zero for now }