MyMathLib series (vector and matrix-preparations)
Because the computing workload of vectors and matrices is relatively large, several definition classes are added here for better code writing. These definitions or extension methods will be applied in future code:
1. Public Enumeration type
/* File: PublicEnums. cs * objective: to define a public Enumeration type. */using System; using System. collections. generic; using System. linq; using System. text; namespace MyMathLib {////// Elementary transformation type (in the textbook, it is a plus, here is a subtraction, just the difference between a coefficient symbol .///Public enum BasicTransMethod {////// Exchange I <=> j ///Swap ,////// Multiply by a non-zero number: I = I * M ///Multipler ,////// Line I minus line j multiplied by a coefficient: I = I-j * M ///CoPlus1 ,////// Multiply line I by the coefficient minus line j by a coefficient: I = I * M1-j * M2 ///CoPlus2 }////// Whether to convert rows or columns .///Public enum TransRowOrCol {////// Row ///Row ,////// Column ///Col} public static class ConstDef {public const int Decimals = 15;} public enum SolutionType {////// No solution ///None ,////// Only zero solution ///OnlyZero, // only one non-zero solution OnlyOne ,////// There are many solutions .///Operator }}
2. equation solving results
/** SolutionOfEquation. cs * Added by Hawksoft. */using System; using System. Collections. Generic; using System. Linq; using System. Text; namespace MyMathLib {////// The solution result of the equation, which is used to store the results after the equations are solved .///Public class SolutionOfEquation {////// Solution type ///Public SolutionType {get; set ;}////// Solution vector ///Public List
SolutionVectors {get; set ;}///
/// Basic unknown quantity ///Public List
PrimaryUnknownVariations {get; set ;}///
/// Free unknown .///Public List
FreeUnknownVariations {get; set;} public SolutionOfEquation () {SolutionVectors = new List
(); PrimaryUnknownVariations = new List
(); FreeUnknownVariations = new List
();}}}
3. Primary transformation record items
Using System; using System. Collections. Generic; using System. Linq; using System. Text; namespace MyMathLib {////// Primary transformation record, used for demonstration of Matrix Elementary Transformation Process and inverse matrix calculation .///Public class TransformItem {public BasicTransMethod TransMethod {get; set;} public int I {get; set;} public int j {get; set;} public double M1 {get; set ;} public double M2 {get; set;} public TransRowOrCol RowOrCol {get; set;} public static TransformItem CreateEleTransRow1 (int I, int j) {return new TransformItem () {I = I, j = j, M1 = 1, TransMethod = BasicTransMethod. swap, RowOrCol = TransRowOrCol. row };} public static TransformItem CreateEleTransRow2 (int I, double Multipler) {return new TransformItem () {I = I, j = I, M1 = Multipler, M2 = Multipler, transMethod = BasicTransMethod. multipler, RowOrCol = TransRowOrCol. row };} public static TransformItem CreateEleTransRow3 (int I, int j, double Multipler) {return new TransformItem () {I = I, j = j, M1 = Multipler, m2 = Multipler, TransMethod = BasicTransMethod. coPlus1, RowOrCol = TransRowOrCol. row };} public static TransformItem CreateEleTransRow4 (int I, int j, double M1, double M2) {return new TransformItem () {I = I, j = j, M1 = M1, m2 = M2, TransMethod = BasicTransMethod. coPlus2, RowOrCol = TransRowOrCol. row };} public static TransformItem CreateEleTransCol1 (int I, int j) {return new TransformItem () {I = I, j = j, M1 = 1, M2 = 1, transMethod = BasicTransMethod. swap, RowOrCol = TransRowOrCol. row };} public static TransformItem CreateEleTransCol2 (int I, double Multipler) {return new TransformItem () {I = I, j = I, M1 = Multipler, M2 = Multipler, transMethod = BasicTransMethod. multipler, RowOrCol = TransRowOrCol. row };} public static TransformItem CreateEleTransCol3 (int I, int j, double Multipler) {return new TransformItem () {I = I, j = j, M1 = 1, m2 = Multipler, TransMethod = BasicTransMethod. coPlus1, RowOrCol = TransRowOrCol. row };} public static TransformItem CreateEleTransCol4 (int I, int j, double M1, double M2) {return new TransformItem () {I = I, j = j, M1 = M1, m2 = M2, TransMethod = BasicTransMethod. coPlus2, RowOrCol = TransRowOrCol. row };}}
In addition, decimal has been used for calculation. However, in the matrix calculation test, it is found that decimal is prone to warehouse explosion. Therefore, the double type is used. In fact, decimal has more digits than double, however, due to its particularity, its expression range is smaller than double, so it is changed to double later.