Esempio n. 1
0
            public static PointF[] Normal(ICalculadora calc, string expresionX, string expresionY, Intervalo intervalo, uint puntosPorUnidad)
            {
                PointF[] puntos;
                int numtotal = ((int)Math.Round((Math.Abs(intervalo.Fin - intervalo.Inicio) * puntosPorUnidad),0, MidpointRounding.AwayFromZero) + 1);

                try
                {
                    puntos = new PointF[numtotal];

                    for (int k = 0; k < calc.Variables.Count; k++)
                    {
                        calc.Variables[calc.Variables.Keys[k]] = intervalo.Inicio;
                    }

                    for (int i = 0; i < puntos.Length; i++)
                    {
                        puntos[i].X = (float)calc.EvaluarExpresion(expresionX);
                        puntos[i].Y = (float)calc.EvaluarExpresion(expresionY);

                        float a = 1f / (float)(puntosPorUnidad);

                        for (int j = 0; j < calc.Variables.Count; j++)
                        {
                            calc.Variables[calc.Variables.Keys[j]] += a;
                        }
                    }

                    return puntos;
                }
                catch (Exception ex)
                {
                    throw ex;
                    //PointF[] po = new PointF[]{PointF.Empty};
                    //return po;
                }
            }
Esempio n. 2
0
            /// <summary>
            /// Genera un MetodoCalculoDelegate que hace derivadas de la variable deseada. El delegado encapsula un método anónimo por lo que el rendimiento se puede ver deteriorado. Es preferible crear un método propio en vez de usar este.
            /// </summary>
            /// <param name="calc">Calculadora que se va a utilizar</param>
            /// <param name="expresionX">Expresion para PointF.X</param>
            /// <param name="expresionY">Expresion para PointF.Y</param>
            /// <param name="variableADerivar">Identificador de la variable a Derivar (Debe estar ya definida en la Calculadora)</param>
            /// <param name="intervalo">Intervalo de Cálculo</param>
            /// <param name="puntosPorUnidad">Puntos a calcular por unidad</param>
            /// <returns>MetodoCalculoDelegate</returns>
            public static MetodoCalculoDelegate GenerarMetodoDerivada(ICalculadora calc, string expresionX, string expresionY, string variableADerivar, Intervalo intervalo, uint puntosPorUnidad)
            {
                return delegate(ICalculadora calcu, string expresX, string expresY, Intervalo interv, uint PPU)
                {
                    PointF[] puntos;

                    try
                    {
                        puntos = new PointF[(int)Math.Round((Math.Abs(intervalo.Fin - intervalo.Inicio) * puntosPorUnidad), 0, MidpointRounding.AwayFromZero)];

                        for (int k = 0; k < calc.Variables.Count; k++)
                        {
                            calc.Variables[calc.Variables.Keys[k]] = intervalo.Inicio;
                        }

                        for (int i = 0; i < puntos.Length; i++)
                        {
                            puntos[i].X = (float)calc.EvaluarExpresion(expresionX);
                            puntos[i].Y = (float)calc.EvaluarDerivada1(expresionY, variableADerivar);

                            float a = 1f / (float)(puntosPorUnidad);

                            for (int j = 0; j < calc.Variables.Count; j++)
                            {
                                calc.Variables[calc.Variables.Keys[j]] += a;
                            }
                        }

                        return puntos;
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                        //PointF[] po = new PointF[]{PointF.Empty};
                        //return po;
                    }
                };
            }