Esempio n. 1
0
        public Matrix(int rows, int cols, Frac val)
        {
            if (rows < 1 || cols < 1)
            {
                throw new OverflowException();
            }

            tab = Extensions.Repeat(val, rows, cols);
        }
Esempio n. 2
0
        public static Frac FracSum <TSource>(this IEnumerable <TSource> source, Func <TSource, Frac> selector)
        {
            Frac sum = Frac.zero;

            foreach (TSource elem in source)
            {
                sum += selector(elem);
            }

            return(sum);
        }
Esempio n. 3
0
        public static Frac FracSum(this IEnumerable <Frac> source)
        {
            Frac sum = Frac.zero;

            foreach (Frac frac in source)
            {
                sum += frac;
            }

            return(sum);
        }
Esempio n. 4
0
        public static Matrix Multiply(Matrix a, Frac b)
        {
            Matrix mult = new Matrix(a);

            for (int i = 0; i < mult.Rows; i++)
            {
                for (int j = 0; j < mult.Cols; j++)
                {
                    mult.tab[i, j] *= b;
                }
            }

            return(mult);
        }
Esempio n. 5
0
        public Frac[] GetCol(int col)
        {
            if (col < 0 || col >= Cols)
            {
                throw new ArgumentOutOfRangeException();
            }

            Frac[] line = new Frac[Rows];

            for (int i = 0; i < Rows; i++)
            {
                line[i] = tab[i, col];
            }

            return(line);
        }
Esempio n. 6
0
        public Frac[] GetRow(int row)
        {
            if (row < 0 || row >= Rows)
            {
                throw new ArgumentOutOfRangeException();
            }

            Frac[] line = new Frac[Cols];

            for (int i = 0; i < Cols; i++)
            {
                line[i] = tab[row, i];
            }

            return(line);
        }
Esempio n. 7
0
        public void RemoveCol(int col)
        {
            if (Cols == 1 || col < 0 || col >= Cols)
            {
                throw new ArgumentOutOfRangeException();
            }

            Frac[,] resize = new Frac[Rows, Cols - 1];

            for (int i = 0; i < Rows; i++)
            {
                for (int j = 0; j < Cols - 1; j++)
                {
                    resize[i, j] = tab[i, j + (j < col ? 0 : 1)];
                }
            }

            tab = resize;
        }
Esempio n. 8
0
        public void RemoveRow(int row)
        {
            if (Rows == 1 || row < 0 || row >= Rows)
            {
                throw new ArgumentOutOfRangeException();
            }

            Frac[,] resize = new Frac[Rows - 1, Cols];

            for (int i = 0; i < Rows - 1; i++)
            {
                for (int j = 0; j < Cols; j++)
                {
                    resize[i, j] = tab[i + (i < row ? 0 : 1), j];
                }
            }

            tab = resize;
        }
Esempio n. 9
0
        public static Matrix Multiply(Matrix a, Matrix b)
        {
            if (a.Cols != b.Rows)
            {
                throw new ArgumentOutOfRangeException();
            }

            Matrix mult = new Matrix(a.Rows, b.Cols);

            for (int i = 0; i < a.Rows; i++)
            {
                for (int j = 0; j < b.Cols; j++)
                {
                    Frac sum = 0;
                    for (int k = 0; k < a.Cols; k++)
                    {
                        sum += a.tab[i, k] * b.tab[k, j];
                    }
                    mult.tab[i, j] = sum;
                }
            }

            return(mult);
        }
Esempio n. 10
0
 public bool Contains(Frac f)
 {
     return(tab.Contains(f));
 }