Example #1
0
    public void calculateCoefficients(Vector <double> xarr, double tprev, double tnow)
    {             // Calculate the coefficients for the solver
        // Explicit method
        //	A = Vector<double> (xarr.Size, xarr.MinIndex, 0.0);
        //	C = A;
        //	B = Vector<double> (xarr.Size, xarr.MinIndex, 1.0);

        a   = new Vector <double> (xarr.Size - 2, xarr.MinIndex + 1, 0.0);
        bb  = new Vector <double> (xarr.Size - 2, xarr.MinIndex + 1, 0.0);
        c   = new Vector <double> (xarr.Size - 2, xarr.MinIndex + 1, 0.0);
        RHS = new Vector <double> (xarr.Size - 2, xarr.MinIndex + 1, 0.0);

        double tmp1, tmp2;
        double k = tnow - tprev;
        double h = xarr[xarr.MinIndex + 1] - xarr[xarr.MinIndex];

        for (int j = xarr.MinIndex + 1; j <= xarr.MaxIndex - 1; j++)
        {
            tmp1 = k * (pde.sigma(xarr[j], tprev) / (h * h));
            tmp2 = k * (pde.mu(xarr[j], tprev) * 0.5 / h);

            a[j]   = tmp1 - tmp2;
            bb[j]  = 1.0 - (2.0 * tmp1) + (k * pde.b(xarr[j], tprev));
            c[j]   = tmp1 + tmp2;
            RHS[j] = k * pde.f(xarr[j], tprev);
        }
    }
Example #2
0
        // Calculate the coefficient at given time point
        public void calculateCoefficients(Vector <double> xarr, double tprev, double tnow)
        {
            // Explicit method
            a = Vector <double> .Build.Dense(xarr.Count - 1, 0.0);

            bb = Vector <double> .Build.Dense(xarr.Count, 0.0);

            c = Vector <double> .Build.Dense(xarr.Count - 1, 0.0);

            rhs = Vector <double> .Build.Dense(xarr.Count, 0.0);

            L = Matrix <double> .Build.Dense(xarr.Count, xarr.Count);

            double k = tnow - tprev; //Time step size

            // Interior
            for (int i = 0; i < xarr.Count; i++)
            {
                bb[i] = 1 - k * (pde.mu(xarr[i], tprev) * beta[1][i] + pde.sigma(xarr[i], tprev) * delta[1][i]);

                rhs[i] = k * pde.f(xarr[i], tprev);

                if (i < xarr.Count - 1)
                {
                    L[i, i + 1] = -k * (pde.mu(xarr[i], tprev) * beta[2][i] + pde.sigma(xarr[i], tprev) * delta[2][i]);
                }
                L[i, i] = bb[i];
                if (i > 0)
                {
                    L[i, i - 1] = -k * (pde.mu(xarr[i], tprev) * beta[0][i] + pde.sigma(xarr[i], tprev) * delta[0][i]);
                }
            }
            // Boundaries
            //L[0, 0] = 1 - k * (pde.mu(xarr[i], tprev) * beta[1][i] + pde.sigma(xarr[0], tprev) * delta[1][0]); ;
            Console.WriteLine(L.ToString());
        }
Example #3
0
        // Calculate the coefficient at given time point
        private void calculateCoefficients(double tprev, double tnow)
        {
            double k  = tnow - tprev; //Time step size
            double dX = xarr[1] - xarr[0];

            // Interior
            for (int i = 0; i < xarr.Count - 1; i++)
            {
                c[i]    = -Math.Pow(pde.sigma(xarr[i], tprev), 2) / Math.Pow(dX, 2) - pde.f(xarr[i], tprev);
                A[i, i] = c[i];
                if (i != xarr.Count() - 1)
                {
                    u[i]        = 0.5 * pde.mu(xarr[i], tprev) / dX + 0.5 * pde.sigma(xarr[i], tprev) / Math.Pow(dX, 2);
                    A[i, i + 1] = u[i];
                }
                if (i != 0)
                {
                    l[i]        = -0.5 * pde.mu(xarr[i], tprev) / dX + 0.5 * pde.sigma(xarr[i], tprev) / Math.Pow(dX, 2);
                    A[i, i - 1] = l[i];
                }
            }
        }