Example #1
0
 public double a(fx A_0, double A_1)
 {
     if (this.d.ContainsKey((int) A_0))
     {
         return this.d[(int) A_0];
     }
     return A_1;
 }
Example #2
0
        private static fx[] SearchNearestNum(fx[] x, double val)
        {
            fx[] fxs = new fx[2];

            fxs[0] = new fx(); fxs[1] = new fx();

            #region fxs[0]
            fxs[0].x = x[0].x;
            fxs[0].f = x[0].f;
            int ind = 0;

            for (int i = 1; i < x.Length; i++)
            {
                if (Math.Abs(fxs[0].x - val) > Math.Abs(x[i].x - val))
                {
                    fxs[0].f = x[i].f;
                    fxs[0].x = x[i].x;
                    ind      = i;
                }
            }
            #endregion

            #region fsx[1]
            if (ind != 0)
            {
                fxs[1].x = x[0].x;
                fxs[1].f = x[0].f;
            }
            else
            {
                fxs[1].x = x[1].x;
                fxs[1].f = x[1].f;
            }
            for (int i = 0; i < x.Length; i++)
            {
                if (Math.Abs(fxs[1].x - val) > Math.Abs(x[i].x - val) && i != ind)
                {
                    fxs[1].f = x[i].f;
                    fxs[1].x = x[i].x;
                }
            }
            #endregion


            if (fxs[0].x < fxs[1].x)
            {
                double X = fxs[0].x;
                double F = fxs[0].f;

                fxs[0].x = fxs[1].x;
                fxs[0].f = fxs[1].f;

                fxs[1].x = X;
                fxs[1].f = F;
            }
            return(fxs);
        }
Example #3
0
 void Start()
 {
     effects = GameObject.FindWithTag("Audio");
     fx = effects.GetComponent<fx>();
     rnd = this.GetComponent<SpriteRenderer>(); //incializa el sprite renderer
     rnd.sprite = escogerSprite(); //asigna el sprite al renderer
     vidas = GameObject.FindWithTag("vidas"); //inicializa el contador de vidas
     lives = vidas.GetComponent<vidas>(); //obtiene la variable de vidas del contador de vidas
     perder = true; //permite perder una vida tras pasar la distancia de la camara hacia abajo
 }
Example #4
0
 static fx[] VectorToFx(Vector x)
 {
     fx[] fxs = new fx[x.Length];
     for (int i = 0; i < x.Length; i++)
     {
         fxs[i]   = new fx();
         fxs[i].x = i;
         fxs[i].f = x[i];
     }
     return(fxs);
 }
        public static double Xirr(IList <CashItem> cashItems)
        {
            var firstItem = cashItems[0];
            fx  seed      = x => 0.0;
            var fxTotal   = cashItems.Aggregate(seed, (current, cashItem) => Compose(current, f(cashItem, firstItem)));
            var dfxTotal  = cashItems.Aggregate(seed, (current, cashItem) => Compose(current, df(cashItem, firstItem)));

            var xirr = NewtonsMethod(fxTotal, dfxTotal, Guess);

            return(xirr);
        }
Example #6
0
        private static fx total_df_xirr(double[] payments, double[] days)
        {
            fx resf = (double x) => 0.0;

            for (int i = 0; i < payments.Length; i++)
            {
                resf = composeFunctions(resf, df_xirr(payments[i], days[i], days[0]));
            }

            return(resf);
        }
Example #7
0
        private static double NewtonsMethod(fx f, fx df, double guess)
        {
            var x0  = guess;
            var err = 1e+100;

            while (err > Tolerance)
            {
                var x1 = x0 - f(x0) / df(x0);
                err = Math.Abs(x1 - x0);
                x0  = x1;
            }
            return(x0);
        }
Example #8
0
        public double Newtons_method(double guess, fx f, fx df)
        {
            double x0 = guess;
            double x1 = 0.0;
            double err = 1e+100;

            while (err > tol)
            {
                x1 = x0 - f(x0) / df(x0);
                err = Math.Abs(x1 - x0);
                x0 = x1;
            }

            return x0;
        }
Example #9
0
        private static double Newtons_method(double guess, fx f, fx df)
        {
            double x0  = guess;
            double x1  = 0.0;
            double err = 1e+100;

            while (err > tol)
            {
                x1  = x0 - f(x0) / df(x0);
                err = Math.Abs(x1 - x0);
                x0  = x1;
            }

            return(x0);
        }
Example #10
0
        public static double Xirr(double guess, fx f, fx df)
        {
            double x0 = guess;
            double x1 = 0.0;
            double err = 1e+100;

            while (err > tol)
            {
                x1 = x0 - f(x0) / df(x0);
                err = Math.Abs(x1 - x0);
                x0 = x1;
            }

            return x0;
        }
        private static double NewtonsMethod(fx f, fx df, double guess)
        {
            var x0  = guess;
            var err = 1e+100;

            while (err > Tolerance)
            {
                var fx0  = f(x0);
                var dfx0 = df(x0);
                // check dfx == 0 !
                var x1 = (Math.Abs(dfx0 - 0) < double.Epsilon) ? x0 / 2 : x0 - fx0 / dfx0;
                err = Math.Abs(x1 - x0);
                x0  = x1;
            }
            return(x0);
        }
Example #12
0
 public static void displayThatView(this Form fx)
 {
     if (fx == null || fx.IsDisposed)
     {
         Form fy = new fx();
         fx.Show;
     }
     else
     {
         if (!fx.Visible)
         {
             fx.Show;
             fx.Activate();
         }
         else
         {
             fx.Activate();
         }
     }
 }
Example #13
0
 public bool a(fx A_0)
 {
     return this.d.ContainsKey((int) A_0);
 }
Example #14
0
 private static fx composeFunctions(fx f1, fx f2)
 {
     return((double x) => f1(x) + f2(x));
 }
 private static fx Compose(fx f1, fx f2)
 {
     return(x => f1(x) + f2(x));
 }
Example #16
0
        public static Vector Taylor(Vector x, Vector y, Vector X, int accuracy = 3)
        {
            Vector xPreproc = new Vector(accuracy);
            Vector yPreproc = new Vector(xPreproc.Length);
            int    sh       = x.Length / accuracy;
            int    b        = 0;

            for (int i = 0; i < accuracy; i++)
            {
                xPreproc[i] = x.GetInterval(b, b + sh - 1).AverageValue();
                yPreproc[i] = y.GetInterval(b, b + sh - 1).AverageValue();
                b          += sh;
            }
            //x = xPreproc;
            //y = yPreproc;

            Vector res = new Vector(X.Length);

            if (x.Length < accuracy)
            {
                accuracy = x.Length;
            }

            fx[][] derivs = new fx[accuracy - 1][];
            for (int i = 0; i < derivs.Length; i++)
            {
                derivs[i] = new fx[x.Length - i - 1];
            }


            for (int i = 0; i < derivs.Length; i++)
            {
                for (int j = 0; j < derivs[i].Length; j++)
                {
                    derivs[i][j] = new fx();
                }
            }

            if (derivs.Length > 0)
            {
                for (int i = 1; i < x.Length; i++)
                {
                    derivs[0][i - 1].f = (y[i] - y[i - 1]) / (x[i] - x[i - 1]);
                    derivs[0][i - 1].x = x[i - 1] + (x[i] - x[i - 1]) / 2.0;
                }
                for (int i = 1; i < derivs.Length; i++)
                {
                    for (int j = 1; j < derivs[i - 1].Length; j++)
                    {
                        derivs[i][j - 1].x = derivs[i - 1][j - 1].x + (derivs[i - 1][j].x - derivs[i - 1][j - 1].x) / 2.0;
                        derivs[i][j - 1].f = (derivs[i - 1][j].f - derivs[i - 1][j - 1].f) / (derivs[i - 1][j].x - derivs[i - 1][j - 1].x);
                    }
                }
            }
            for (int i = 0; i < X.Length; i++)
            {
                Vector deriv = new Vector(accuracy);
                var    index = SearchNearestInd(x, X[i]);
                deriv[0] = y[index];
                double a = x[index];
                Vector A = new Vector(accuracy);
                A[0] = a;
                for (int k = 1; k < A.Length; k++)
                {
                    A[k] = derivs[k - 1][SearchNearestInd(derivs[k - 1], X[i])].x;
                }
                for (int j = 0; j < accuracy - 1; j++)
                {
                    deriv[j + 1] = SearchNearestVal(derivs[j], X[i]);
                }
                //res[i] = matlib.Function.Polynomials.Taylor(X[i], a, deriv);

                if (accuracy < 1)
                {
                    return(null);
                }

                double result = 0.0;
                for (int n = 0; n < deriv.Length; n++)
                {
                    result += deriv[n] * Math.Pow(X[i] - A[0], n) / (double)matlib.Factorial(n);
                }

                res[i] = result;
            }
            return(res);
        }
Example #17
0
 public fx composeFunctions(fx f1, fx f2)
 {
     return (double x) => f1(x) + f2(x);
 }
Example #18
0
 public static fx composeFunctions(fx f1, fx f2)
 {
     return (double x) => f1(x) + f2(x);
 }