Ejemplo n.º 1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // Make two triangular arrays.
            const int          numRows = 3;
            TriangularIntArray array1  = new TriangularIntArray(numRows);

            array1[0, 0] = 1;
            array1[1, 0] = 2;
            array1[1, 1] = 3;
            array1[2, 0] = 4;
            array1[2, 1] = 5;
            array1[2, 2] = 6;

            TriangularIntArray array2 = new TriangularIntArray(numRows);

            array2[0, 0] = 10;
            array2[1, 0] = 20;
            array2[1, 1] = 30;
            array2[2, 0] = 40;
            array2[2, 1] = 50;
            array2[2, 2] = 60;

            TriangularIntArray array3 = array1.TimesFull(array2);
            TriangularIntArray array4 = array1.Times(array2);

            resultTextBox.Text =
                array1.ToString() + Environment.NewLine +
                array2.ToString() + Environment.NewLine +
                array3.ToString() + Environment.NewLine +
                array4.ToString();
            resultTextBox.Select(0, 0);
        }
Ejemplo n.º 2
0
        // Multiply this array on the right by another array.
        public TriangularIntArray Times(TriangularIntArray other)
        {
            TriangularIntArray result = new TriangularIntArray(this.NumRows);

            for (int i = 0; i < NumRows; i++)
            {
                for (int j = 0; j < NumRows; j++)
                {
                    // Calculate the [i, j] entry.
                    int total = 0;
                    for (int k = j; k <= i; k++)
                    {
                        total += this[i, k] * other[k, j];
                    }
                    result[i, j] = total;
                }
            }
            return(result);
        }