Exemple #1
0
        void izracunaj_polinom(int izrac_tab_local)
        {
            #region init_matrice
            conn.Close();
            int     n    = 0;
            tocke[] temp = new tocke[100];
            for (int i = 0; i < pol[izrac_tab_local].br_tocki; i++)
            {
                temp[n].x = pol[izrac_tab_local].zadanetocke[i].X;
                temp[n].y = pol[izrac_tab_local].zadanetocke[i].Y;
                n++;
            }
            double[][] matrica = new double[n + 1][];
            for (int j = 0; j < n; j++)
            {
                double[] temp_red = new double[n + 1];
                temp_red[n] = temp[j].y;
                for (int i = 0; i < n; i++)
                {
                    temp_red[n - 1 - i] = Math.Pow(temp[j].x, i);
                }
                matrica[j] = temp_red;
            }
            #endregion
            #region make_le_string
            Thread.CurrentThread.CurrentCulture       = new CultureInfo("hr-HR");
            pol[izrac_tab_local].kaeficjent_xa_na_itu = new Double[n + 2];
            mematka nekaj   = new mematka();
            tocke[] nekakve = nekaj.izrac_func(temp, pol[izrac_tab_local].mode, n);
            if (pol[izrac_tab_local].mode == 0)
            {
                for (int i = 0; i < n; i++)
                {
                    pol[izrac_tab_local].kaeficjent_xa_na_itu[(int)nekakve[i].x] = nekakve[i].y;
                }
            }
            else if (pol[izrac_tab_local].mode == 1)
            {
                pol[izrac_tab_local].MinDif = 0;
                if (nekakve != null)
                {
                    if (nekakve.Length > 1)
                    {
                        pol[izrac_tab_local].MinDif = nekakve[1].x;
                    }
                    for (int i = 0; i < n; i++)
                    {
                        pol[izrac_tab_local].kaeficjent_xa_na_itu[i] = nekakve[i].y;
                    }
                }
            }

            make_graf(izrac_tab_local);
            #endregion
        }
Exemple #2
0
        public tocke[] izrac_func(tocke[] temp, int mode, int n)
        {
            if (n == 0)
            {
                return(null);
            }
            tocke[]    rje     = new tocke[n];
            double[][] matrica = new double[n - 1][];
            tocke      nul     = new tocke();

            #region sort
            for (int i = 0; i < n; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    if (temp[j].x < temp[i].x)
                    {
                        tocke tmp = temp[i];
                        temp[i] = temp[j];
                        temp[j] = tmp;
                    }
                }
            }
            #endregion
            #region odabir
            if (mode == 0)
            {
                for (int i = 0; i < n; i++)
                {
                    if (temp[i].x == 0)
                    {
                        tocke tm = temp[i];
                        temp[i]     = temp[n - 1];
                        temp[n - 1] = tm;
                        break;
                    }
                }
                #region init_matrix
                matrica = new double[n][];
                for (int j = 0; j < n; j++)
                {
                    double[] temp_red = new double[n + 1];
                    temp_red[n] = temp[j].y;
                    for (int i = 0; i < n; i++)
                    {
                        temp_red[n - 1 - i] = Math.Pow(temp[j].x, i);
                    }
                    matrica[j] = temp_red;
                }
                #endregion
            }
            dif = (MathHelper.TwoPi) / ((temp[n - 1].x - temp[0].x));
            if (mode == 1)
            {
                if (n == 1)
                {
                    tocke[] r = new tocke[1];
                    r[0].y = temp[0].y;
                    r[0].x = 0;
                    return(r);
                }
                #region init_matrix

                for (int j = 0; j < (n - 1); j++)
                {
                    double[] temp_red = new double[n];
                    temp_red[n - 1] = temp[j].y;
                    temp_red[0]     = 1;
                    for (int i = 1; i < (n - 1); i++)
                    {
                        temp_red[i] = Math.Sin(temp[j].x * (i * dif));
                    }
                    matrica[j] = temp_red;
                }
                #endregion
            }
            #endregion
            #region prema_dole
            for (int i = 0; i < (n - mode); i++)
            {
                for (int j = i + 1; j < (n - mode); j++)
                {
                    double koeficjent = matrica[j][i] / matrica[i][i];
                    //matrica[j][i] = 0;

                    for (int k = 0; k < (n + 1 - mode); k++)
                    {
                        matrica[j][k] = matrica[j][k] - (koeficjent * matrica[i][k]);
                    }
                }
            }

            #endregion
            #region prema_gore
            for (int i = n - 1 - mode; i >= 0; i--)
            {
                for (int j = i - 1; j >= 0; j--)
                {
                    double koeficjent = new double();
                    koeficjent           = matrica[j][i] / matrica[i][i];
                    matrica[j][i]        = 0;
                    matrica[j][n - mode] = matrica[j][n - mode] - koeficjent * matrica[i][n - mode];
                }
            }
            #endregion
            #region make_rj
            if (mode == 1)
            {
                for (int i = 0; i < (n - 1); i++)
                {
                    double broj = matrica[i][n - 1] / matrica[i][i];
                    rje[i].x = dif * (i);
                    rje[i].y = broj;
                }
            }
            else if (mode == 0)
            {
                for (int i = 0; i < n; i++)
                {
                    double broj = matrica[i][n] / matrica[i][i];
                    rje[i].x = (n - 1 - i);
                    rje[i].y = broj;
                }
            }
            #endregion


            return(rje);
        }
Exemple #3
0
        public void izracunaj_polinom(int izrac_tab_local, int izrac_tab_global)
        {
            #region init_matrice

            if (th.IsAlive && th.Priority < ThreadPriority.AboveNormal)
            {
                graf.e_treba = true;
                th.Priority  = ThreadPriority.AboveNormal;
            }
            OleDbDataAdapter tempad  = new OleDbDataAdapter("SELECT * FROM postavke WHERE id = " + izrac_tab_global.ToString(), conn);
            DataSet          temp_ds = new DataSet();
            tempad.Fill(temp_ds);
            int modeer = Convert.ToInt32(temp_ds.Tables[0].Rows[0][2]);
            //OleDbDataAdapter tempad = new OleDbDataAdapter("SELECT * FROM tocke" + Convert.ToInt32(medataset.Tables[0].Rows[izrac_tab][1]), conn);
            tempad  = new OleDbDataAdapter("SELECT * FROM tocke" + izrac_tab_global.ToString(), conn);
            temp_ds = new DataSet();
            tempad.Fill(temp_ds);

            int     n    = 0;
            tocke[] temp = new tocke[100];
            for (int i = 0; i < temp_ds.Tables[0].Rows.Count; i++)
            {
                bool b = Convert.ToBoolean(temp_ds.Tables[0].Rows[i][3]);
                if (b == true)
                {
                    temp[n].x = Convert.ToDouble(temp_ds.Tables[0].Rows[i][1], CultureInfo.GetCultureInfo("hr-HR"));
                    temp[n].y = Convert.ToDouble(temp_ds.Tables[0].Rows[i][2], CultureInfo.GetCultureInfo("hr-HR"));
                    n++;
                }
            }
            #endregion
            mematka nekaj   = new mematka();
            tocke[] nekakve = nekaj.izrac_func(temp, modeer, n);

            Label temp_lb = (Label)this.Controls[izrac_tab_local.ToString()].Controls[2];
            temp_lb.Text = nekaj.string_func(nekakve, modeer, p);
            OleDbCommand up = new OleDbCommand("UPDATE postavke SET func = '" + temp_lb.Text + "' WHERE id = " + izrac_tab_global + ";", conn);
            try {
                conn.Open();
            }catch (Exception ee) {
                if (Debug)
                {
                    MessageBox.Show(ee.ToString());
                }
            }
            try {
                up.ExecuteNonQuery();
            }
            catch (Exception ee)
            {
                if (Debug)
                {
                    MessageBox.Show(ee.ToString());
                }
            }
            try {
                conn.Close();
            }catch (Exception ee) {
                if (Debug)
                {
                    MessageBox.Show(ee.ToString());
                }
            }
        }