예제 #1
0
        public float dot(RNVector vec)
        {
            float dotSum = 0;

            for (int i = 0; i < components.Count; i++)
            {
                dotSum += components[i] * vec.components[i];
            }
            return(dotSum);
        }
예제 #2
0
        public Matrix mult(Matrix m2)
        {
            List <RNVector> rowVectors  = new List <RNVector>();
            List <RNVector> rowVectors2 = new List <RNVector>();

            //get rows of first matrix
            for (int i = 0; i < MRows.Count; i++)
            {
                RNVector rN = new RNVector(MRows[i]);
                rowVectors.Add(rN);
            }

            //get cols of second matrix
            for (int x = 0; x < m2.MRows[0].Count; x++)
            {
                List <float> colComps = new List <float>();
                for (int y = 0; y < m2.MRows.Count; y++)
                {
                    colComps.Add(m2.MRows[y][x]);
                }

                RNVector rN = new RNVector(colComps);
                rowVectors2.Add(rN);
            }

            //same number of cols as second matrix
            int cols = m2.MRows[0].Count;

            List <float> orderedEntries = new List <float>();

            //same number of rows as first matrix
            for (int i = 0; i < MRows.Count; i++)
            {
                for (int c = 0; c < cols; c++)
                {
                    orderedEntries.Add(rowVectors[i].dot(rowVectors2[c]));
                }
            }

            return(new Matrix(orderedEntries, cols));
        }