예제 #1
0
    // Add Lattice to the spreadsheet with row and column labels.
    public void AddLattice(string name, Lattice <double> lattice, List <string> rowLabels)
    {
        try
        {
            // Check label count vs. matrix.

            /*     if (lattice.Columns != columnLabels.Count)
             *   {
             *       throw (new IndexOutOfRangeException("Count mismatch between # matrix columns and # column labels"));
             *   }
             *   if (lattice.Rows != rowLabels.Count)
             *   {
             *       throw (new IndexOutOfRangeException("Count mismatch between # matrix rows and # row labels"));
             *   }
             */
            // Add sheet.
            Excel.Workbook  pWorkbook;
            Excel.Worksheet pSheet;
            if (pExcel.ActiveWorkbook == null)
            {
                pWorkbook = (Excel.Workbook)InvokeMethodInternational(pExcel.Workbooks, "Add", Excel.XlWBATemplate.xlWBATWorksheet);
                pSheet    = (Excel.Worksheet)pWorkbook.ActiveSheet;
            }
            else
            {
                pWorkbook = pExcel.ActiveWorkbook;
                pSheet    = (Excel.Worksheet)InvokeMethodInternational(pWorkbook.Worksheets, "Add", Type.Missing, Type.Missing, 1, Type.Missing);
            }
            pSheet.Name = name;

            // Add row labels + values.
            int sheetColumn = 1;
            int sheetRow    = 1;
            for (int i = lattice.MinIndex; i <= lattice.MaxIndex; i++)
            {
                Vector <double> row = lattice.PyramidVector(i);
                ToSheetHorizontal <double>(pSheet, sheetRow, sheetColumn, rowLabels[i - lattice.MinIndex], row);
                sheetRow++;
            }

            for (int i = lattice.MinIndex; i <= lattice.MaxIndex; i++)
            {
                Vector <double> row = lattice.PyramidVector(i);
                ToSheetHorizontal <double>(pSheet, sheetRow, sheetColumn, rowLabels[i], row);
                sheetRow++;
                // sheetColumn++;
            }
        }
        catch (IndexOutOfRangeException e)
        {
            Console.WriteLine("Exception: " + e);
        }
    }
예제 #2
0
        // Add Lattice to the spreadsheet with row and column labels.
        public void AddLattice(string name, Lattice <double> lattice, List <string> rowLabels)
        {
            try
            {
                // Check label count vs. matrix.

                /*     if (lattice.Columns != columnLabels.Count)
                 *   {
                 *       throw (new IndexOutOfRangeException("Count mismatch between # matrix columns and # column labels"));
                 *   }
                 *   if (lattice.Rows != rowLabels.Count)
                 *   {
                 *       throw (new IndexOutOfRangeException("Count mismatch between # matrix rows and # row labels"));
                 *   }
                 */

                // Add sheet.
                ExcelWorksheet pSheet = _pExcel.Workbook.Worksheets.Add(name);

                // Add row labels + values.
                int sheetColumn = 1;
                int sheetRow    = 1;
                for (int i = lattice.MinIndex; i <= lattice.MaxIndex; i++)
                {
                    Vector <double> row = lattice.PyramidVector(i);
                    ToSheetHorizontal <double>(pSheet, sheetRow, sheetColumn, rowLabels[i - lattice.MinIndex], row);
                    sheetRow++;
                }

                for (int i = lattice.MinIndex; i <= lattice.MaxIndex; i++)
                {
                    Vector <double> row = lattice.PyramidVector(i);
                    ToSheetHorizontal <double>(pSheet, sheetRow, sheetColumn, rowLabels[i], row);
                    sheetRow++;
                    // sheetColumn++;
                }
            }
            catch (IndexOutOfRangeException e)
            {
                Console.WriteLine("Exception: " + e);
            }
        }
    public static void Main()
    {
        int typeB = 2;  // Binomial Lattice Type
        int typeT = 3;  // Trinomial Lattice Type

        int depth = 4;  // Number of periods of time

        double val = 4.0;

        Lattice <double> lattice1 = new Lattice <double>(depth, typeB, val);
        Lattice <double> lattice2 = new Lattice <double>(depth, typeT, val);


        // Examining the vector at base of lattice
        Vector <double> base1 = lattice1.BasePyramidVector();
        Vector <double> base2 = lattice2.BasePyramidVector();

        // Print columms of lattice
        for (int j = lattice1.MinIndex; j <= lattice1.MaxIndex; j++)
        {
            lattice1.PyramidVector(j).print();
        }

        string s = Console.ReadLine();

        // Arrays
        int             startIndex = lattice1.MinIndex;
        Vector <double> xarr       = new Vector <double>(depth + 1, startIndex);

        xarr[xarr.MinIndex] = 0.0;
        double T       = 1.0;
        int    NT      = 10;
        double delta_T = T / NT;

        for (int j = xarr.MinIndex + 1; j <= xarr.MaxIndex; j++)
        {
            xarr[j] = xarr[j - 1] + delta_T;
        }

        Console.WriteLine(base1.Size); Console.WriteLine(base2.Size);

        ExcelMechanisms exl = new ExcelMechanisms();

        try
        {
            exl.printLatticeInExcel(lattice2, xarr, "Lattice");
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }
    }