예제 #1
0
        public Matrice Putere(int x)
        {
            int     n = a.GetLength(0);
            Matrice C = new Matrice(n, n);

            if (n != a.GetLength(1))
            {
                Console.WriteLine("Nu se poate ridica la putere");
                return(C);
            }
            if (x == 0)
            {
                for (int i = 0; i < n; i++)
                {
                    C.a[i, i] = 1;
                }
            }
            else if (x == 1)
            {
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        C.a[i, j] = a[i, j];
                    }
                }
            }
            else
            {
                C = C.Inmultire(C.Putere(x - 1));
            }
            return(C);
        }
예제 #2
0
        public Matrice Inversa()
        {
            int     n = a.GetLength(0);
            Matrice C = new Matrice(n, n);

            if (n != a.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.a[l, k] = a[k + 1, l + 1];
                                }
                                else if (k >= i && l < j)
                                {
                                    A.a[l, k] = a[k + 1, l];
                                }
                                else if (k < 1 && l >= j)
                                {
                                    A.a[l, k] = a[k, l + 1];
                                }
                                else
                                {
                                    A.a[l, k] = a[k, l];
                                }
                            }
                        }
                        A.Afisare();
                        A.CalculDeterminant();
                        C.a[i, j] = (int)Math.Pow(-1, i + j) * A.determinant;
                        Console.WriteLine(C.a[i, j]);
                    }
                }
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < n; j++)
                    {
                        C.a[i, j] *= 1f / determinant;
                    }
                }
            }
            return(C);
        }
예제 #3
0
        public Matrice Scadere(Matrice B)
        {
            int     n = a.GetLength(0), m = a.GetLength(1);
            Matrice C = new Matrice(n, m);

            if (n != B.a.GetLength(0) || m != B.a.GetLength(1))
            {
                Console.WriteLine("Nu se pot scadea");
            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    for (int j = 0; j < m; j++)
                    {
                        C.a[i, j] = a[i, j] - B.a[i, j];
                    }
                }
            }
            return(C);
        }
예제 #4
0
        static void Main(string[] args)
        {
            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(2);
            C.Afisare();
            C = B.Inversa();
            C.Afisare();
            Console.ReadKey();
        }
예제 #5
0
        public Matrice Inmultire(Matrice B)
        {
            int     n = a.GetLength(0), m = a.GetLength(1);
            Matrice C = new Matrice(n, n);

            if (n != B.a.GetLength(1))
            {
                Console.WriteLine("Nu se pot inmulti");
            }
            else
            {
                for (int k = 0; k < n; k++)
                {
                    for (int i = 0; i < n; i++)
                    {
                        for (int j = 0; j < m; j++)
                        {
                            C.a[k, i] += a[i, j] * B.a[j, i];
                        }
                    }
                }
            }
            return(C);
        }