Пример #1
0
        public LinkedList <string[]> solucion()
        {
            double ValStarta = evaluator.EvalVar(ValStarta1);
            double ValStartb = evaluator.EvalVar(ValStartb1);
            double pm;
            double fa;
            double fb;
            double fpm;
            int    it = 0;


            LinkedList <string[]> Resultado = new LinkedList <string[]>();

            do
            {
                pm  = ValStarta + ((ValStartb - ValStarta) / 2);
                fa  = evaluator.EvalFunction(Expresion, ValStarta);
                fb  = evaluator.EvalFunction(Expresion, ValStartb);
                fpm = evaluator.EvalFunction(Expresion, pm);

                //data.Rows.Add(it, ValStarta, ValStartb, pm, fa, fb, fpm); saludos
                string[] IterationVals = new string[7];

                IterationVals[0] = Convert.ToString(it);
                IterationVals[1] = Convert.ToString(ValStarta);
                IterationVals[2] = Convert.ToString(ValStartb);
                IterationVals[3] = Convert.ToString(pm);
                IterationVals[4] = Convert.ToString(fa);
                IterationVals[5] = Convert.ToString(fb);
                IterationVals[6] = Convert.ToString(fpm);

                Resultado.AddLast(IterationVals);

                if (fpm * fa < 0)
                {
                    ValStartb = pm;
                }
                else if (fpm * fb < 0)
                {
                    ValStarta = pm;
                }
                else
                {
                    pm = -1;
                    break;
                }
                it++;
            } while (it <= Iteration && Tolerance < Math.Abs(((ValStartb - ValStarta) / 2)));

            Root = pm;

            return(Resultado);
        }
        public LinkedList <string[]> solucion()
        {
            int    it = 2;
            double q  = 0;
            double q0 = 0;
            double q1 = 0;
            double p0 = evaluator.EvalVar(ValStarta);
            double P;
            double p1 = evaluator.EvalVar(ValStartb);

            LinkedList <string[]> Resultado = new LinkedList <string[]>();

            string[] IterationVals = new string[3];
            q0 = evaluator.EvalFunction(Expresion, p0);
            q1 = evaluator.EvalFunction(Expresion, p1);

            do
            {
                P = p1 - q1 * (p1 - p0) / (q1 - q0);

                IterationVals    = new string[3];
                IterationVals[0] = Convert.ToString(it);
                IterationVals[1] = Convert.ToString(P);
                IterationVals[2] = Convert.ToString(Math.Abs(P - p1));

                Resultado.AddLast(IterationVals);

                it++;
                q = evaluator.EvalFunction(Expresion, P);

                if (q - q1 < 0)
                {
                    p0 = p1;
                    q0 = q1;
                }

                p1 = P;
                q1 = q;
            } while (it <= Iteration && Math.Abs(P - p1) < Tolerance);

            Root = P;

            return(Resultado);
        }
Пример #3
0
        public LinkedList <string[]> solucion()
        {
            int    it  = 1;
            double x   = evaluator.EvalVar(ValStarta);
            double aux = 0;
            double fx  = 0;
            double dfx = 0;

            LinkedList <string[]> Resultado = new LinkedList <string[]>();

            string[] IterationVals = new string[6];

            do
            {
                aux = x;

                fx  = evaluator.EvalFunction(Expresion, x);
                dfx = evaluator.EvalFunction(Derivate, x);

                x = Math.Round(x - (fx / dfx), 7);

                IterationVals = new string[6];

                //Falta clase para separar datos
                IterationVals[0] = Convert.ToString(it);
                IterationVals[4] = Convert.ToString(x);
                IterationVals[1] = Convert.ToString(aux);
                IterationVals[2] = Convert.ToString(fx);
                IterationVals[3] = Convert.ToString(dfx);
                IterationVals[5] = Convert.ToString(aux - x);
                Resultado.AddLast(IterationVals);

                it++;
            } while (it <= Iteration && Math.Abs(aux - x) > Tolerance);

            Root = x;

            return(Resultado);
        }