コード例 #1
0
ファイル: main.cs プロジェクト: asnkneajpboylz/PROG
    static int Main()
    {
        int n = 40;
        int N = 100;

        double[] x = new double[n];
        double[] y = new double[n];
        int      i;

//change
        for (i = 0; i < n; i++)
        {
            x[i] = 2 * PI * i / (n - 1);
            y[i] = Sin(x[i]);
            //WriteLine("equidistant points of sine {0:g6} {1:g6}", x[i],y[i]);
        }

        Write("\n");
        var    cs   = new cspline(x, y);
        var    qua  = new quadspline(x, y);
        var    cub  = new cubespline(x, y);
        double z    = x[0];
        double step = (x[n - 1] - x[0]) / (N - 1);

        for (i = 0; i < N; i++)
        {
            z = x[0] + i * step;
            WriteLine($"{z} {cs.eval(z)} {cs.integ(z)} {qua.eval(z)} {qua.integ(z)} {qua.derive(z)} {cub.eval(z)} {cub.integ(z)} {cub.derive(z)}");
        }

        //	Write($"test integration of sine from 0 to 2pi: {cs.integ(2*PI)}\n");
        //	Write($"evaluate interpol sin at pi/2, pi: {cs.eval(PI/2)} {cs.eval(PI)}\n");
        return(0);
    }
コード例 #2
0
    public static int Main(string[] args)
    {
        if (args.Length != 2)
        {
            return(1);
        }

        // The two input parameters will be the name of the file with the table values
        // and the amount of lines in that file
        string filein = args[0];
        int    nlines = int.Parse(args[1]);

        StreamReader streamin = new StreamReader(filein);

        double[] xs = new double[nlines];
        double[] ys = new double[nlines];

        for (int i = 0; i < nlines; i++)
        {
            string line = streamin.ReadLine();

            // There is a third value in each line (the integral from x[0] to z), but we
            // do not need the value here
            string[] numbers = line.Split('\t');
            xs[i] = double.Parse(numbers[0]);
            ys[i] = double.Parse(numbers[1]);
        }

        streamin.Close();


        // Interpolate the data
        double xstart  = xs[0];
        double xend    = xs[nlines - 1];
        double deltax  = 0.02;
        var    qspline = new quadspline(xs, ys);

        for (double k = xstart; k < xend; k += deltax)
        {
            double interpval   = qspline.eval(k);
            double integralval = qspline.integrate(k);
            double derivval    = qspline.deriv(k);

            WriteLine("{0,8:f4}\t{1,8:f4}\t{2,8:f4}\t{3,8:f4}", k, interpval, integralval, derivval);
        }

        return(0);
    }