Exemplo n.º 1
0
        public Matrice Putere(int x)
        {
            int     n = matrix.GetLength(0);
            Matrice C = new Matrice(n, n);

            if (n != matrix.GetLength(1))
            {
                Console.WriteLine("Doar matricile patratice pot avea putere"); return(C);
            }
            if (x == 0)
            {
                for (int i = 0; i < n; i++)
                {
                    C.matrix[i, i] = 1;
                }
            }
            else if (x == 1)
            {
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        C.matrix[i, j] = matrix[i, j];
                    }
                }
            }
            else
            {
                C = C.Inmultire(C.Putere(x - 1));
            }
            return(C);
        }
Exemplo n.º 2
0
        public Matrice Inversa()
        {
            int     n = matrix.GetLength(0);
            Matrice C = new Matrice(n, n);

            if (n != matrix.GetLength(1))
            {
                Console.WriteLine("Doar matricile patratice pot avea inversa"); return(C);
            }
            CalculDeterminant();
            if (determinant != 0)
            {
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        Matrice A = new Matrice(n - 1, n - 1);
                        for (int k = 0; k < n - 1; k++)
                        {
                            for (int l = 0; l < n - 1; l++)
                            {
                                if (k >= i && l >= j)
                                {
                                    A.matrix[l, k] = matrix[k + 1, l + 1];
                                }
                                else if (k >= i && l < j)
                                {
                                    A.matrix[l, k] = matrix[k + 1, l];
                                }
                                else if (k < 1 && l >= j)
                                {
                                    A.matrix[l, k] = matrix[k, l + 1];
                                }
                                else
                                {
                                    A.matrix[l, k] = matrix[k, l];
                                }
                            }
                        }
                        A.Afisare();
                        A.CalculDeterminant();
                        C.matrix[i, j] = (int)Math.Pow(-1, i + j) * A.determinant;
                        Console.WriteLine(C.matrix[i, j]);
                    }
                }
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        C.matrix[i, j] *= 1f / determinant;
                    }
                }
            }
            return(C);
        }
Exemplo n.º 3
0
        public Matrice Scadere(Matrice B)
        {
            int     n = matrix.GetLength(0), m = matrix.GetLength(1);
            Matrice C = new Matrice(n, m);

            if (n != B.matrix.GetLength(0) || m != B.matrix.GetLength(1))
            {
                Console.WriteLine("Nu se pot scadea doua matrici de dimensiuni diferite");
            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        C.matrix[i, j] = matrix[i, j] - B.matrix[i, j];
                    }
                }
            }
            return(C);
        }
Exemplo n.º 4
0
        public Matrice Inmultire(Matrice B)
        {
            int     n = matrix.GetLength(0), m = matrix.GetLength(1);
            Matrice C = new Matrice(n, n);

            if (n != B.matrix.GetLength(1))
            {
                Console.WriteLine("Numarul de coloane al primei matrice trebuie sa fie egal cu numarul de linii al celei de-a doua");
            }
            else
            {
                for (int k = 0; k < n; k++)
                {
                    for (int i = 0; i < n; i++)
                    {
                        for (int j = 0; j < m; j++)
                        {
                            C.matrix[k, i] += matrix[i, j] * B.matrix[j, i];
                        }
                    }
                }
            }
            return(C);
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            //1
            Complex a = new Complex((double)r.Next(10), (double)r.Next(10));
            Complex b = new Complex((double)r.Next(10), (double)r.Next(10));
            int     x = r.Next(10);

            Console.WriteLine("a: {0}, b: {1}", a, b);
            Console.WriteLine("{0} - {1} = {2}", a, b, a - b);
            Console.WriteLine("{0} + {1} = {2}", a, b, a + b);
            Console.WriteLine("{0} * {1} = {2}", a, b, a * b);
            Console.WriteLine("({0})^{1} = {2}", a, x, a.Putere(x));
            b.Trigonometric();
            Console.WriteLine();

            //2
            Rational r1 = new Rational(r.Next(100), r.Next(100));
            Rational r2 = new Rational(r.Next(100), r.Next(100));

            Console.WriteLine("r1: {0}, r2: {1}", r1, r2);
            Console.WriteLine("{0} - {1} = {2}", r1, r2, r1 - r2);
            Console.WriteLine("{0} + {1} = {2}", r1, r2, r1 + r2);
            Console.WriteLine("{0} * {1} = {2}", r1, r2, r1 * r2);
            Console.WriteLine("{0} / {1} = {2}", r1, r2, r1 / r2);
            Console.WriteLine("{0}^{1} = {2}; {3}^{1} = {4}", r1, x, r1.Putere(x), r2, r2.Putere(x));
            Rational R1 = r1; R1.Ireductibil();
            Rational R2 = r2; R2.Ireductibil();

            Console.WriteLine("{0} = {1}; {2} = {3}", r1, R1, r2, R2);
            Console.WriteLine("{0} < {1}: {2}", r1, r2, r1 < r2);
            Console.WriteLine("{0} > {1}: {2}", r1, r2, r1 > r2);
            Console.WriteLine("{0} <= {1}: {2}", r1, r2, r1 <= r2);
            Console.WriteLine("{0} >= {1}: {2}", r1, r2, r1 >= r2);
            Console.WriteLine("{0} == {1}: {2}", r1, r2, r1 == r2);
            Console.WriteLine("{0} != {1}: {2}", r1, r2, r1 != r2);
            Console.WriteLine();

            //3
            Matrice A = new Matrice(3, 3);
            Matrice B = new Matrice(3, 3);

            A.Afisare(); B.Afisare();
            Matrice C = new Matrice(3, 3);

            C = A.Adunare(B); C.Afisare();
            C = A.Scadere(B); C.Afisare();
            C = A.Inmultire(B); C.Afisare();
            C = A.Putere(3); C.Afisare();
            C = B.Inversa(); C.Afisare();

            //1'
            ComplexD zd = new ComplexD(5, 3);
            Complex  D  = new Complex();

            D = zd.Putere(2);
            Console.WriteLine(D);
            Complex[] v = new Complex[2];
            v[0] = new Complex(1, 1);
            v[1] = new Complex(5, 2);
            double d = zd.Distanta(v);

            Console.WriteLine(d);
            Console.ReadKey();
        }