示例#1
0
        public static void Main(String [] args)
        {
            const int         N  = 10;
            TriDiagonalMatrix m1 = new TriDiagonalMatrix(N);
            TriDiagonalMatrix m2 = new TriDiagonalMatrix(N);

            int x = 1;

            for (int row = 0; row < N; row++)
            {
                for (int col = 0; col < N; col++)
                {
                    if (Math.Abs(row - col) <= 1)
                    {
                        m1.set(row, col, 1);
                        m2.set(row, col, x);
                        x++;
                    }
                }
            }

            Console.WriteLine("m1:\n" + m1.CompactPrint());
            Console.WriteLine("m2:\n" + m2.CompactPrint());

            TriDiagonalMatrix m3 = m1 + m2;

            Console.WriteLine("m3:\n" + m3.CompactPrint());
        }
示例#2
0
        public static void Main(String [] args)
        {
            int N = 31;

            TriDiagonalMatrix m = new TriDiagonalMatrix(N);

            float [] b = new float[N];

            for (int row = 0; row < N; row++)
            {
                for (int col = 0; col < N; col++)
                {
                    int diff = Math.Abs(row - col);
                    if (diff == 0)
                    {
                        m.set(row, col, 2);
                    }
                    else if (diff == 1)
                    {
                        m.set(row, col, 1);
                    }
                }
                b[row] = (float)16.0 - (float)Math.Abs((float)(row + 1) - (float)16.0);
            }

            try
            {
                Solver   s = new Solver(m, b);
                float [] x = s.Solve();

                Console.Write("x: ");
                for (int i = 0; i < N; i++)
                {
                    Console.Write((int)Math.Round(x[i], 0) + " ");
                }
                Console.WriteLine();
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e);
            }
        }
示例#3
0
        public static void Main(String [] args)
        {
            const int         N  = 10;
            TriDiagonalMatrix m1 = new TriDiagonalMatrix(N);
            TriDiagonalMatrix m2 = new TriDiagonalMatrix(N);

            int x = 1;

            for (int row = 0; row < N; row++)
            {
                for (int col = 0; col < N; col++)
                {
                    if (Math.Abs(row - col) <= 1)
                    {
                        m1.set(row, col, 1);
                        m2.set(row, col, x);
                        x++;
                    }
                }
            }

            TriDiagonalMatrix m3 = m1 + m2;

            Console.WriteLine("m1:");
            foreach (int v in m1)
            {
                Console.Write(v + " ");
            }
            Console.WriteLine();

            Console.WriteLine("m2:");
            foreach (int v in m2)
            {
                Console.Write(v + " ");
            }
            Console.WriteLine();

            Console.WriteLine("m3:");
            foreach (int v in m3)
            {
                Console.Write(v + " ");
            }
            Console.WriteLine();

            Console.WriteLine("m3:");
            TriDiagonalMatrixEnumerator ie = m3.GetEnumerator();

            while (ie.MoveNext())
            {
                Console.Write(ie.Current + " ");
            }
            Console.WriteLine();
        }
示例#4
0
文件: Tester6.cs 项目: fengb3/cse465
 public static void Main(String [] args)
 {
     try
     {
         TriDiagonalMatrix m = new TriDiagonalMatrix(6);
         m.set(2, -4, 3);
         m.CompactPrint();
     }
     catch (ArgumentException e)
     {
         Console.WriteLine(e);
     }
 }