コード例 #1
0
ファイル: EpMatrix.cs プロジェクト: Epse/EpSets
		/// <summary>
		/// Swaps the two given rows
		/// </summary>
		/// <returns>An EpMatrix with the swap performed</returns>
		/// <param name="matrix">Matrix.</param>
		/// <param name="rowOne">Zero-based index for the first row.</param>
		/// <param name="rowTwo">Zero-based index for the second row.</param>
		public static EpMatrix SwapRows (EpMatrix matrix, int rowOne, int rowTwo)
		{
			// tempstore the two rows, then swap them in TheMatrix
			int[] firstRow = new int[matrix.GetNumOfColumns()-1];
			for (int i = 0; i < matrix.GetNumOfColumns (); i++) {
				firstRow [i] = matrix.GetElement (rowOne, i);
			}

			// Copy the second row into the first one
			for (int i = 0; i < matrix.GetNumOfColumns (); i++) {
				matrix.SetElement (rowOne, i, matrix.GetElement (rowTwo, i));
			}

			// And now the temp into the second row
			for (int i = 0; i < matrix.GetNumOfColumns (); i++) {
				matrix.SetElement (rowOne, i, firstRow [i]);
			}

			return matrix;
		}
コード例 #2
0
ファイル: EpMatrix.cs プロジェクト: Epse/EpSets
		/// <summary>
		/// Adds two rows from the given matrix together. Stores the result in the first row by convention
		/// </summary>
		/// <returns>An EpMatrix with the rows added</returns>
		/// <param name="matrix">Matrix.</param>
		/// <param name="rowOne">Zero-based index for the first row. The result goes in here as well.</param>
		/// <param name="rowTwo">Zero-based index for the second row.</param>
		public static EpMatrix AddRows (EpMatrix matrix, int rowOne, int rowTwo)
		{
			for (int i = 0; i < matrix.GetNumOfColumns (); i++) {
				matrix.SetElement (rowOne, i, matrix.GetElement (rowTwo, i) + matrix.GetElement (rowOne, i));
			}

			return matrix;
		}
コード例 #3
0
ファイル: EpMatrix.cs プロジェクト: Epse/EpSets
		/// <summary>
		/// Performs a linear combination on two rows. Stores the result in the first row by convention.
		/// </summary>
		/// <returns>EpMatrix with the combination performed on it</returns>
		/// <param name="matrix">Matrix.</param>
		/// <param name="rowOne">Zero-based index for the first row</param>
		/// <param name="factorOne">Factor to multiply the first rwo by</param>
		/// <param name="rowTwo">Zero-based index for the second row</param>
		/// <param name="factorTwo">Factor to multiply the second row by</param>
		public static EpMatrix LinearCombination (EpMatrix matrix, int rowOne, int factorOne, int rowTwo, int factorTwo)
		{
			for (int i = 0; i < matrix.GetNumOfColumns (); i++) {
				matrix.SetElement (rowOne, i, 
					factorOne * matrix.GetElement (rowOne, i) + factorTwo * matrix.GetElement (rowTwo, i));
			}

			return matrix;
		}
コード例 #4
0
ファイル: EpMatrix.cs プロジェクト: Epse/EpSets
		/// <summary>
		/// Multiplies two rows together.
		/// </summary>
		/// <returns>An EpMatrix with the operation performed on it.</returns>
		/// <param name="matrix">Matrix.</param>
		/// <param name="theRow">Zero-based index for the row.</param>
		/// <param name="factor">Factor.</param>
		public static EpMatrix MultiplyRow (EpMatrix matrix, int theRow, int factor)
		{
			for (int i = 0; i < matrix.GetNumOfColumns (); i++) {
				matrix.SetElement (theRow, i, matrix.GetElement (theRow, i) * factor);
			}

			return matrix;
		}