C#,数值计算——数据建模FGauss的计算方法与源程序

1 文本格式

using System;

namespace Legalsoft.Truffer
{
    public class FGauss : MultiFuncd
    {
        public void funk(double x, double[] a, ref double y, double[] dyda)
        {
            int na = a.Length;
            y = 0.0;
            for (int i = 0; i < na - 1; i += 3)
            {
                double arg = (x - a[i + 1]) / a[i + 2];
                double ex = Math.Exp(-Globals.SQR(arg));
                double fac = a[i] * ex * 2.0 * arg;
                y += a[i] * ex;
                dyda[i] = ex;
                dyda[i + 1] = fac / a[i + 2];
                dyda[i + 2] = fac * arg / a[i + 2];
            }
        }

        public static double[] fpoly(double x)
        {
            int fpoly_np = 10;
            double[] p = new double[fpoly_np];
            p[0] = 1.0;
            for (int j = 1; j < fpoly_np; j++)
            {
                p[j] = p[j - 1] * x;
            }
            return p;
        }

        public static double[] fleg(double x)
        {
            int fleg_nl = 10;
            double[] pl = new double[fleg_nl];
            pl[0] = 1.0;
            pl[1] = x;
            if (fleg_nl > 2)
            {
                double twox = 2.0 * x;
                double f2 = x;
                double d = 1.0;
                for (int j = 2; j < fleg_nl; j++)
                {
                    double f1 = d++;
                    f2 += twox;
                    pl[j] = (f2 * pl[j - 1] - f1 * pl[j - 2]) / d;
                }
            }
            return pl;
        }

    }
}
 

2 代码格式

using System;

namespace Legalsoft.Truffer
{
    public class FGauss : MultiFuncd
    {
        public void funk(double x, double[] a, ref double y, double[] dyda)
        {
            int na = a.Length;
            y = 0.0;
            for (int i = 0; i < na - 1; i += 3)
            {
                double arg = (x - a[i + 1]) / a[i + 2];
                double ex = Math.Exp(-Globals.SQR(arg));
                double fac = a[i] * ex * 2.0 * arg;
                y += a[i] * ex;
                dyda[i] = ex;
                dyda[i + 1] = fac / a[i + 2];
                dyda[i + 2] = fac * arg / a[i + 2];
            }
        }

        public static double[] fpoly(double x)
        {
            int fpoly_np = 10;
            double[] p = new double[fpoly_np];
            p[0] = 1.0;
            for (int j = 1; j < fpoly_np; j++)
            {
                p[j] = p[j - 1] * x;
            }
            return p;
        }

        public static double[] fleg(double x)
        {
            int fleg_nl = 10;
            double[] pl = new double[fleg_nl];
            pl[0] = 1.0;
            pl[1] = x;
            if (fleg_nl > 2)
            {
                double twox = 2.0 * x;
                double f2 = x;
                double d = 1.0;
                for (int j = 2; j < fleg_nl; j++)
                {
                    double f1 = d++;
                    f2 += twox;
                    pl[j] = (f2 * pl[j - 1] - f1 * pl[j - 2]) / d;
                }
            }
            return pl;
        }

    }
}

你可能感兴趣的:(C#数值计算,Numerical,Recipes,c#,算法,数值计算,开发语言)