示例#1
0
        // IComparable
        public int CompareTo(Monom <T> other)
        {
            int compareRes = Degree.CompareTo(other.Degree);

            if (compareRes != 0)
            {
                return(compareRes);
            }
            return(Coef.CompareTo(other.Coef));
        }
示例#2
0
        //Using ToString instead of ToStringSimplified might be better when doing math operations
        public override string ToString()
        {
            string coef = "", var = "", pow = "";

            coef = Coef.ToString();
            pow  = "^" + Power.ToString();
            if (!VariableSymbol.Equals(DefaultVariableSymbol))
            {
                var = VariableSymbol.ToString();
            }
            return(string.Format("{0}{1}{2}", coef, var, pow));
        }
示例#3
0
 public override bool Equals(object obj)
 {
     if (this == obj)
     {
         return(true);
     }
     if (obj is Monom <T> another)
     {
         return(Coef.Equals(another.Coef) && Degree.Equals(another.Degree));
     }
     else
     {
         return(false);
     }
 }
示例#4
0
 public bool SetAvrSetCoefDt()
 {
     if (audysseyMultEQAvrTcpClientWithTimeout != null)
     {
         // data for each speaker... this is a very dumb binary data pump... payload must be SECRET!
         foreach (Int32[] Coef in _audysseyMultEQAvr.CoefData)
         {
             // transmit packets in chunks of 512 bytes
             int total_byte_packets = (Coef.Length * 4) / 512;
             // the last packet may have less than 512 bytes
             int last_packet_length = Coef.Length - (total_byte_packets * 128);
             // count for all packets
             if (last_packet_length > 0)
             {
                 total_byte_packets++;
             }
             // transmit all the packets
             for (int current_packet = 0; current_packet < total_byte_packets; current_packet++)
             {
                 Int32[] CopyData = current_packet < total_byte_packets - 1 ? new int[128] : new int[last_packet_length];
                 Array.Copy(Coef, current_packet * 128, CopyData, 0, current_packet < total_byte_packets - 1 ? 128 : last_packet_length);
                 bool   CheckSumChecked = false;
                 string CmdString       = "SET_COEFDT";
                 Console.Write(CmdString);
                 Console.WriteLine(Coef.ToString());
                 // transmit request
                 audysseyMultEQAvrTcpClientWithTimeout.TransmitTcpAvrStream(CmdString, audysseyMultEQAvrTcpClientWithTimeout.Int32ToByte(CopyData), current_packet, total_byte_packets - 1);;
                 string AvrString;
                 // receive rseponse
                 audysseyMultEQAvrTcpClientWithTimeout.ReceiveTcpAvrStream(ref CmdString, out AvrString, out CheckSumChecked);
                 Console.Write(CmdString);
                 Console.WriteLine(AvrString);
                 // success if all succeed
                 if (false == (CmdString.Equals("SET_COEFDT") && AvrString.Equals(ACK) && CheckSumChecked))
                 {
                     return(false);
                 }
             }
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
示例#5
0
        double[] Solve(Coef a, int n, double y0, double yn)//a,b,c,f - резмеры n+1 от 0 до n
        {
            //метод прогонки, a - коэффициенты перед i-1 членом, b перед i, c перед i+1, d - неоднородность
            int i;

            double[] alpha = new double[n + 1];
            double[] beta  = new double[n + 1];
            double[] y     = new double[n + 1];
            alpha[1] = 0;
            beta[1]  = y0;
            for (i = 1; i < n; i++)
            {
                alpha[i + 1] = -a.C[1] / (a.A[1] * alpha[i] + a.B[1]);
                beta[i + 1]  = (a.F[1] - a.A[1] * beta[i]) / (a.A[1] * alpha[i] + a.B[1]);
            }
            y[0] = y0;
            y[n] = yn;
            for (i = n - 1; i > 0; i--)
            {
                y[i] = alpha[i + 1] * y[i + 1] + beta[i + 1];
            }
            return(y);
        }
示例#6
0
        public void InitMono()
        {
            numericUpDownK.Maximum            = (M = Hset.Count) + 1;
            numericUpDownK.Enabled            = M > 1;
            ToolStripMenuItemEvaluate.Enabled = SumAbc != Abc.Zero;
            string text2 = @"F[a,b,c,z]";

            /*
             * if(domainUpDownA.SelectedIndex == 3)
             *      text2 = text2.Replace(@"a", numericUpDownA.Value.ToString(CultureInfo.InvariantCulture));
             * if(domainUpDownB.SelectedIndex == 3)
             *      text2 = text2.Replace(@"b", numericUpDownB.Value.ToString(CultureInfo.InvariantCulture));
             * if(domainUpDownC.SelectedIndex == 3)
             *      text2 = text2.Replace(@"c", numericUpDownC.Value.ToString(CultureInfo.InvariantCulture));
             * //*/
            labelFs.Text = Coef.GetShiftedStr(text2, Hset.List.Data[1].AbcShift + ShiftAbc, false);
            labelF0.Text = Coef.GetShiftedStr(text2, ShiftAbc, false);
            Coef cf = new Coef(string.Concat(@"-(",
                                             Hset.List.Data[0].StrFunc, @")/(",
                                             Hset.List.Data[1].StrFunc, @")"))[ShiftAbc].Simplify();

            ContFrac = new ContinuedFractionA(SumAbc, new MonoLinker <Coef>(cf));
            string text1 = cf.StrFunc;

            text2 = Coef.One.StrFunc;

            /*
             * if(domainUpDownA.SelectedIndex == 3)
             *      text1 = text1.Replace(@"a", numericUpDownA.Value.ToString(CultureInfo.InvariantCulture));
             * if(domainUpDownB.SelectedIndex == 3)
             *      text1 = text1.Replace(@"b", numericUpDownB.Value.ToString(CultureInfo.InvariantCulture));
             * if(domainUpDownC.SelectedIndex == 3)
             *      text1 = text1.Replace(@"c", numericUpDownC.Value.ToString(CultureInfo.InvariantCulture));
             * text1 = Expression.Simplify(Expression.Simplify(text1), Coef.SortComparison);
             * //*/
            var product = Expression.SplitSum(text1);

            if (product.Link == null)
            {
                product = Expression.SplitProduct(text1);
                text1   = text2;
                foreach (var v in (IEnumerable <KeyValuePair <char, string> >)product)
                {
                    if (v.Key == '/')
                    {
                        text2 += string.Concat(@"*(", v.Value, @")");
                    }
                    else
                    {
                        text1 += string.Concat(@"*(", v.Value, @")");
                    }
                }
            }
            textBox1.Text = Expression.Simplify(text1, Coef.SortComparison);
            textBox2.Text = Expression.Simplify(text2, Coef.SortComparison);
            if (Xi == null)
            {
                InitPanelXi();
            }
            Abc abc = ShiftAbc;

            foreach (var he in Hset)
            {
                cf = new Coef(string.Concat(@"-(",
                                            Coef.GetShiftedStr(he.Link.Data[1].StrFunc, he.Data[2].AbcShift, true), @")*(",
                                            he.Data[2].StrFunc, @")/(",
                                            Coef.GetShiftedStr(he.Link.Data[0].StrFunc, he.Data[2].AbcShift, true), @")/(",
                                            he.Data[0].StrFunc, @")"))[abc].Simplify();
                ContFrac.Coefs.Add(cf);
                abc  += he.Data[2].AbcShift;
                text1 = cf[SumAbc * 10000].StrFunc.Replace(@"0000", @"*n");
                text2 = Coef.One.StrFunc;

                /*
                 * if(domainUpDownA.SelectedIndex == 3)
                 *      text1 = text1.Replace(@"a", numericUpDownA.Value.ToString(CultureInfo.InvariantCulture));
                 * if(domainUpDownB.SelectedIndex == 3)
                 *      text1 = text1.Replace(@"b", numericUpDownB.Value.ToString(CultureInfo.InvariantCulture));
                 * if(domainUpDownC.SelectedIndex == 3)
                 *      text1 = text1.Replace(@"c", numericUpDownC.Value.ToString(CultureInfo.InvariantCulture));
                 * text1 = Expression.Simplify(Expression.Simplify(text1), Coef.SortComparison);
                 * //*/
                product = Expression.SplitSum(text1);
                if (product.Link == null)
                {
                    product = Expression.SplitProduct(text1);
                    text1   = text2;
                    foreach (var v in (IEnumerable <KeyValuePair <char, string> >)product)
                    {
                        if (v.Key == '/')
                        {
                            text2 += string.Concat(@"*(", v.Value, @")");
                        }
                        else
                        {
                            text1 += string.Concat(@"*(", v.Value, @")");
                        }
                    }
                }
                Xi.Data.textBoxNumerator.Text   = Expression.Simplify(text1, Coef.SortComparison);
                Xi.Data.textBoxDenominator.Text = Expression.Simplify(text2, Coef.SortComparison);
                Xi = Xi.Link;
            }
            ContFrac.Coefs.GetLast().Link = ContFrac.Coefs.Link;
        }
示例#7
0
 public override string ToString()
 {
     return(NameWorker + " - коэффициент к оплате " + Coef.ToString());
 }
示例#8
0
 private static double Weight(Coef flag)
 {
     return(_weights[flag] / _weights.Values.Sum());
 }
示例#9
0
        public void Compute(bool bDataChanged)
        {
            Phi0  = (double)InitialData["Phi0"];
            Phi1  = (double)InitialData["Phi1"];
            n     = (int)InitialData["n"];
            L     = (double)InitialData["L"];
            po    = (double)InitialData["po"];
            Gamma = (double)InitialData["Gamma"];
            U     = (double)InitialData["U"];
            double     Pe = po * U * L / Gamma;
            int        i;
            LineSeries ser0 = new LineSeries();

            ser0.Title = this.Name + "Anal";
            LineSeries ser1 = new LineSeries();

            ser1.Title = this.Name + "CDS";//здесь и в следующих 2 - аппроксимация диффузного члена
            LineSeries ser2 = new LineSeries();

            ser2.Title = this.Name + "UDS";
            LineSeries ser3 = new LineSeries();

            ser3.Title = this.Name + "CDSalt";
            LineSeries ser4 = new LineSeries();

            ser4.Title = this.Name + "UDSalt";
            double[] x  = new double [n + 1];
            double[] y0 = new double[n + 1];
            double[] y1 = new double[n + 1];
            double[] y2 = new double[n + 1];
            double[] y3 = new double[n + 1];
            double   h  = L / (n);

            for (i = 0; i < n + 1; i++)
            {
                x[i]  = i * L / (n);
                y0[i] = Phi0 + ((Math.Exp(x[i] * Pe / L) - 1) / (Math.Exp(Pe) - 1)) * (Phi1 - Phi0);
            }

            //A*коэффициент перед yi-1+*коэффициент перед yi+C*коэффициент перед yi+1 = F; Первое значение - это нулевой коэффт(i=0), второе - это при i от 1 до n-2 и третье при i=n-1
            Coef   Y1   = new Coef();
            double adif = -2 * Gamma / (2 * h * h);
            double cdif = -2 * Gamma / (2 * h * h);
            double bdif = (adif + cdif) * (-1);
            double aUDS = (Math.Max(po * U, 0)) / h;//2h
            double cUDS = (Math.Min(po * U, 0)) / h;
            double bUDS = (aUDS + cUDS) * (-1);
            double aCDS = -po * U / (2 * h);
            double cCDS = po * U / (2 * h);
            double bCDS = 0;
            double a    = aCDS + adif;
            double b    = bCDS + bdif;
            double c    = cCDS + cdif;

            double[] A0 = new double[] { 0, a, 0 };
            double[] B0 = new double[] { 1, b, 1 };
            double[] C0 = new double[] { 0, c, 0 };
            double[] F0 = new double[] { Phi0, 0, Phi1 };
            Y1.init(A0, B0, C0, F0);
            y1 = Solve(Y1, n, Phi0, Phi1);
            Coef Y2 = new Coef();

            a = adif - aUDS;
            b = bdif - bUDS;
            c = cdif - cUDS;
            double[] A = new double[] { 0, a, 0 };
            double[] B = new double[] { 1, b, 1 };
            double[] C = new double[] { 0, c, 0 };
            double[] F = new double[] { 0, 0, 1 };
            Y2.init(A, B, C, F);
            y2 = Solve(Y2, n, Phi0, Phi1);

            for (i = 0; i <= n; i++)
            {
                ser0.Points.Add(new OxyPlot.DataPoint(x[i], y0[i]));
                ser1.Points.Add(new OxyPlot.DataPoint(x[i], y1[i]));
                ser2.Points.Add(new OxyPlot.DataPoint(x[i], y2[i]));
            }

            ListBasePlotSeries plot_ser  = new ListBasePlotSeries("x", "-", "y", "-", ser0);
            ListBasePlotSeries plot_ser1 = new ListBasePlotSeries("x", "-", "y", "-", ser1);
            ListBasePlotSeries plot_ser2 = new ListBasePlotSeries("x", "-", "y", "-", ser2);


            m_results = new SimplePlotResult();
            m_results.AddSeries(plot_ser);
            m_results.AddSeries(plot_ser1);
            m_results.AddSeries(plot_ser2);
        }
示例#10
0
 public void InverseAdditive() => Coef.InverseAdditive();
示例#11
0
 public void Divide(Monom <T> another)
 {
     Coef.Divide(another.Coef);
     Degree -= another.Degree;
 }
示例#12
0
 public void Multiply(Monom <T> another)
 {
     Coef.Multiply(another.Coef);
     Degree += another.Degree;
 }
示例#13
0
 // ICloneable
 public object Clone() => new Monom <T>((T)Coef.Clone(), Degree);