コード例 #1
0
ファイル: Root.cs プロジェクト: MrKuznetsov/hw-cpp
        public override float findRoot(Segment ab, Polynomial F, float e)
        {
            float a = ab.a;
            float b = ab.b;
            float fa, fb, fc;

            //N = 0;

            while (true)
            {
                fa = F.f(a);
                fb = F.f(b);
                fc = F.f((a + b) / 2.0f);

                if ((b - a) < 2 * e)
                    break;
                if (fc == 0)
                    break;
               //     System.Console.WriteLine("x = {0} {1}", b-a, 2 * e);
              //  N++;

                if (fa * fc < 0)
                    b = (a + b) / 2.0f;
                else
                    a = (a + b) / 2.0f;
            }
            return (a + b) / 2.0f;
        }
コード例 #2
0
        public void Div()
        {
            float h      = mh;
            int   lCount = -1; // prev segments count
            int   count  = 0;  //curent count

            float a = ma;
            float b = 0;

            bool calcH = false;

            if (h < 0) // if we need to calculate h automatic
            {
                h     = (mb - ma) / 5.0f;
                calcH = true;
            }
            while (true) // for auto calc
            {
                count = 0;
                a     = ma;
                mSegments.Clear();

                while (a < mb)
                {
                    b = Math.Min(mb, a + h);
                    if ((mFunc.f(a)) * (mFunc.f(b)) < 0)
                    {
                        count++;
                        mSegments.Add(new Segment(a, b));
                    }
                    a = b;
                }

                if (!calcH)
                {
                    break;
                }

                if ((count == lCount) || (h < MINH))
                {
                    break;
                }
                lCount = count;
                h     /= 11.3f;
            }

            mh = h;
        }
コード例 #3
0
        override public float findRoot(Segment ab, Polynomial F, float e)
        {
            float a = ab.a;
            float b = ab.b;
            float fa, fb, fc;

            //N = 0;

            while (true)
            {
                fa = F.f(a);
                fb = F.f(b);
                fc = F.f((a + b) / 2.0f);

                if ((b - a) < 2 * e)
                {
                    break;
                }
                if (fc == 0)
                {
                    break;
                }
                //     System.Console.WriteLine("x = {0} {1}", b-a, 2 * e);
                //  N++;

                if (fa * fc < 0)
                {
                    b = (a + b) / 2.0f;
                }
                else
                {
                    a = (a + b) / 2.0f;
                }
            }
            return((a + b) / 2.0f);
        }