コード例 #1
0
ファイル: main.cs プロジェクト: ryejakob/prog
    static int Main()
    {
        //test of  cubicspline using Sin(x)

        int n = 11; //number of sample points

        //generate sample points:
        vector x      = new vector(n);
        vector y      = new vector(n);
        var    points = new System.IO.StreamWriter("points.txt");

        for (int i = 0; i < n; i++)
        {
            x[i] = 2 * i * (PI / (n - 1));
            y[i] = Sin(x[i]);
            points.WriteLine($"{x[i]} {y[i]}");
        }        //end for
        points.Close();

        //using qspline

        cspline csin = new cspline(x, y);

        //generating data to plot
        var data = new System.IO.StreamWriter("data.txt");
        int N    = 100;

        for (int i = 0; i < N; i++)
        {
            double xn = 2 * i * (PI / (N - 1));
            data.WriteLine($"{xn} {Sin(xn)} {csin.c_spline(xn)} {Cos(xn)} {csin.cderivative(xn)} {1-Cos(xn)} {csin.cintegral(xn)}");
        }        //end for
        data.Close();

        //end of test using sine

        WriteLine($"Part C:");
        WriteLine($"Cubic spline of Sin(x) can be seen in cubic_splineC.svg.");
        WriteLine($"The derivative of the aforementioned spline of can be seen in cubic_derivativeC.svg, and the integral in cubic_integralC.svg");
        WriteLine($"In comparisonC.svg my the calculated cubic spline is compared with spline from plotutils");



        return(0);
    }
コード例 #2
0
ファイル: main_2.cs プロジェクト: ryejakob/prog
    static int Main(string[] args)
    {
        // input to vector...
        var input        = new System.IO.StreamReader("sin_data.txt");
        int input_lenght = 0;

        while (input.ReadLine() != null)
        {
            input_lenght++;
        }
        input.Close();
        input = new System.IO.StreamReader("sin_data.txt");
        vector x1 = new vector(input_lenght);
        vector y1 = new vector(input_lenght);

        string line;

        for (int n = 0; n < input_lenght; n++)
        {
            line = input.ReadLine();
            string[] words = line.Split(' ');
            x1[n] = double.Parse(words[0]);
            y1[n] = double.Parse(words[1]);
        }
        /// end input to vector
        cspline a = new cspline(x1, y1);

        for (double n = 0; n <= 10; n += 0.05)
        {
            WriteLine($"{n} {a.cderivative(n)}");
        }



        return(0);
    }