static void Main(string[] args)
        {
            Random rand = new Random();

            double[] yDatapoints = new double[3];
            for (int i = 0; i < 3; i++)
            {
                yDatapoints[i] = rand.Next(20, 60);
            }
            double[,] xAll = new double[12, 3];
            for (int i = 0; i < 12; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    xAll[i, j] = rand.Next(2, 100);
                }
            }
            Microsoft.Office.Interop.Excel.Application       xl  = new Microsoft.Office.Interop.Excel.Application();
            Microsoft.Office.Interop.Excel.WorksheetFunction wsf = xl.WorksheetFunction;
            object[,] result = (object[, ])wsf.LinEst(yDatapoints, xAll, Type.Missing, true);
        }
Beispiel #2
0
        private void LineanTrade()
        {
            #region Линейный тип
            Microsoft.Office.Interop.Excel.Application       xl  = new Microsoft.Office.Interop.Excel.Application();
            Microsoft.Office.Interop.Excel.WorksheetFunction wsf = xl.WorksheetFunction;
            Series series3 = new Series("Линейный тренд", ViewType.Line);
            chartControl1.Series.Add(series3);
            series3.ArgumentScaleType = ScaleType.Numerical;
            series3.ValueScaleType    = ScaleType.Numerical;

            int      ch    = 0;
            int      ch1   = 0;
            int      ch2   = 0;
            int      ch3   = 1;
            int      count = dataGridView1.RowCount;
            double[] x     = new double[count];
            double   x1    = 0;
            double[] y     = new double[count];
            double[] yY    = new double[count];
            for (int k = 0; k < count; k++)
            {
                x[k] = Convert.ToDouble(dataGridView1.Rows[k].Cells[3].Value);
                y[k] = Convert.ToDouble(dataGridView1.Rows[k].Cells[2].Value);
                ch++;
            }
            for (int k = 0; k < count; k++)
            {
                object[,] lin1 = wsf.LinEst(y, x, 1, 1);
                var b1 = lin1[1, 1];
                var a1 = lin1[1, 2];
                x1    = Convert.ToDouble(dataGridView1.Rows[k].Cells[3].Value);
                yY[k] = Math.Round(Convert.ToDouble(a1) + Convert.ToDouble(x1 * Convert.ToDouble(b1)), 2);
                ch3++;
            }
            for (int k = 0; k < yY.Length; k++)
            {
                ch2++;
                series3.Points.Add(new SeriesPoint(ch2, yY[k]));
            }
            TrendLine      trendline1 = new TrendLine("Линейный тренд");
            LineSeriesView myView     = ((LineSeriesView)series3.View);
            myView.AxisY.WholeRange.AlwaysShowZeroLevel = false;
            trendline1.ExtrapolateToInfinity            = false;
            trendline1.Color = Color.Red;
            int t = trendline1.Weight;
            t = 3;
            trendline1.ShowInLegend        = false;
            trendline1.Visible             = false;
            trendline1.LineStyle.DashStyle = DashStyle.Dash;
            myView.Indicators.Add(trendline1);

            try
            {
                object[,] lin1 = wsf.LinEst(y, x, 1, 1);
                var    b1  = lin1[1, 1];
                var    a1  = lin1[1, 2];
                double yY1 = Math.Round(Convert.ToDouble(a1) + Convert.ToDouble((ch + 1) * Convert.ToDouble(b1)), 2);
                textBox2.Text = yY1.ToString();
                chartControl1.Series[1].Points.Add(new SeriesPoint((ch + 1), yY1));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ФАНЗ");
                return;
            }

            for (int jk = 0; jk < x.Length; jk++)
            {
                ch1++;
                chartControl1.Series[0].Points.Add(new SeriesPoint(ch1, Convert.ToDouble(dataGridView1[2, jk].Value)));
            }
            #endregion
        }
Beispiel #3
0
        private void PowTrade()
        {
            #region Степенная регрессия
            Microsoft.Office.Interop.Excel.Application       xl    = new Microsoft.Office.Interop.Excel.Application();
            Microsoft.Office.Interop.Excel.WorksheetFunction wsf   = xl.WorksheetFunction;
            Microsoft.Office.Interop.Excel.WorksheetFunction index = xl.WorksheetFunction;
            Microsoft.Office.Interop.Excel.WorksheetFunction exp   = xl.WorksheetFunction;

            Series series3 = new Series("Степенной тренд", ViewType.Spline);
            chartControl1.Series.Add(series3);
            series3.ArgumentScaleType = ScaleType.Numerical;
            series3.ValueScaleType    = ScaleType.Numerical;
            int      ch    = 0;
            int      ch1   = 0;
            int      ch2   = 0;
            int      ch3   = 1;
            int      count = dataGridView1.RowCount;
            double[] x     = new double[count];
            double   x1    = 0;
            double[] y     = new double[count];
            double[] yY    = new double[count];

            for (int k = 0; k < count; k++)
            {
                x[k] = Math.Log(Convert.ToDouble(dataGridView1.Rows[k].Cells[3].Value));
                y[k] = Math.Log(Convert.ToDouble(dataGridView1.Rows[k].Cells[2].Value));
                ch++;
            }

            for (int k = 0; k < count; k++)
            {
                object[,] lin1 = wsf.LinEst(y, x, 1, 1);
                double c = Math.Exp(wsf.Index((lin1), 1, 2));
                var    b = lin1[1, 1];
                x1    = Convert.ToDouble(dataGridView1.Rows[k].Cells[3].Value);
                yY[k] = Math.Round(c * Math.Pow(x1, Convert.ToDouble(b)), 2);
                ch3++;
            }
            for (int k = 0; k < yY.Length; k++)
            {
                ch2++;
                series3.Points.Add(new SeriesPoint(ch2, yY[k]));
            }
            TrendLine        trendline1 = new TrendLine("Степенной тренд");
            SplineSeriesView myView     = ((SplineSeriesView)series3.View);
            trendline1.ExtrapolateToInfinity = false;
            trendline1.Color               = Color.Red;
            trendline1.ShowInLegend        = false;
            trendline1.Visible             = false;
            trendline1.LineStyle.DashStyle = DashStyle.Dash;
            myView.Indicators.Add(trendline1);
            try
            {
                object[,] lin1 = wsf.LinEst(y, x, 1, 1);
                double c   = Math.Exp(wsf.Index((lin1), 1, 2));
                var    b   = lin1[1, 1];
                double yY1 = Math.Round(c * Math.Pow(ch + 1, Convert.ToDouble(b)), 2);
                textBox2.Text = yY1.ToString();
                chartControl1.Series[1].Points.Add(new SeriesPoint((ch + 1), yY1));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "ФАНЗ");
                return;
            }

            for (int jk = 0; jk < x.Length; jk++)
            {
                ch1++;
                chartControl1.Series[0].Points.Add(new SeriesPoint(ch1, Convert.ToDouble(dataGridView1[2, jk].Value)));
            }
            #endregion
        }