Ejemplo n.º 1
0
        public static bool DiscrepancyIsSmall()
        {
            Random rand          = new Random();
            double changingEntry = rand.Next() % 10;

            double[] entries1 = new double[3] {
                -1, 3, 4
            };
            double[] entries2 = new double[3] {
                -7, 11, changingEntry
            };
            Vector vector1 = new Vector(entries1);
            Vector vector2 = new Vector(entries2);

            Vector[] inputVectors = { vector1, vector2 };
            Basis    inputBasis   = new Basis(inputVectors);
            Compute  compute      = new Compute();

            compute.Gram_Schmidt_Process(inputBasis);
            Vector[] result             = Basis.VectorsOfBasis(compute.orthogonalBasis);
            double   innerProduct       = Vector.FindInnerProduct(result[0], result[1]);
            bool     discrepancyIsSmall = (innerProduct <= 0.01);

            return(discrepancyIsSmall);
        }
Ejemplo n.º 2
0
 public void Gram_Schmidt_Process(Basis inputBasis)
 {
     orthogonalBasis     = new Basis(inputBasis.dim, inputBasis.vectors[0].n);
     orthogonalBasis.dim = inputBasis.dim;
     Vector[] u = Basis.VectorsOfBasis(inputBasis);
     Vector[] v = new Vector[u.Length];
     v[0] = inputBasis.vectors[0];
     double[] zeroVector = Vector.ZeroVector(u[0].n);
     for (int i = 1; i < inputBasis.dim; ++i)
     {
         Vector   deduct        = new Vector(zeroVector);
         Vector[] deductVectors = new Vector[i];
         for (int j = 0; j < i; ++j)
         {
             double innerProduct = Vector.FindInnerProduct(u[i], v[j]);
             double normSquare   = Vector.FindNormSquare(v[j]);
             deductVectors[j] = Vector.ScalarMultiplication(v[j], (innerProduct / normSquare));
         }
         deduct = Vector.VectorArrayAddition(deductVectors);
         v[i]   = Vector.VectorAddition(u[i], Vector.ScalarMultiplication(deduct, (-1)));
     }
     for (int i = 0; i < inputBasis.dim; ++i)
     {
         orthogonalBasis.vectors[i] = v[i];
     }
 }