예제 #1
0
    static void Main()
    {
        // Test.binarySearchTest();
        int          n   = 15;
        vector       xs  = new vector(n);
        vector       ys  = new vector(n);
        StreamWriter val = new StreamWriter("sin_values.txt");

        for (int i = 0; i < n; i++)
        {
            xs[i] = i / 2.0;
            ys[i] = Sin(xs[i]);
            val.Write($"{xs[i],5:f8} {ys[i],10:f12}\n");
        }
        val.Close();

        StreamWriter cSplineWriter = new StreamWriter("sin_cspline.txt");
        cSpline      sinCubSpline  = new cSpline(xs, ys);

        for (double x = 0; x < 7; x += 0.05)
        {
            cSplineWriter.Write($"{x,10:f8} {sinCubSpline.spline(x),15:f16}\n");
        }
        cSplineWriter.Close();

        Write($"Integral from 0 to pi of sin(x) with cubic spline: {sinCubSpline.integral(PI)}\n");
        Write("True result from analytic expression is: 2.00\n");

        Write($"Derivative of sin(x) evaluated at pi/4: {sinCubSpline.derivative(PI/4)}\n");
        Write("True result from analytic expression is: 1/sqrt(2) or 0.707106781186547 \n");
    } //Main
예제 #2
0
        private void GL_OpenGLInitialized(object sender, EventArgs e) // Инициализация библиотеки
        {
            OpenGL gl = GL.OpenGL;
            int    W  = GL.Width;
            int    H  = GL.Height;

            gl.Disable(OpenGL.GL_DEPTH_TEST);

            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.LoadIdentity();
            gl.Ortho(0, W, 0, H, -1, 1);
            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.LoadIdentity();

            CentrX = W / 2;
            CentrY = H / 2;

            short w    = (short)W;
            short h    = (short)H;
            short cx   = (short)CentrX;
            short cy   = (short)CentrY;
            short step = (short)GridStep;
            int   len  = (w + h) / step + 2;

            VerGrid    = new short[len * 4];
            VerGrid[0] = cx; VerGrid[1] = 0; VerGrid[2] = cx; VerGrid[3] = h;
            VerGrid[4] = 0; VerGrid[5] = cy; VerGrid[6] = w; VerGrid[7] = cy;
            int pos = 8;

            for (short x = (short)(cx + step); x < w; x += step)
            {
                VerGrid[pos++] = x; VerGrid[pos++] = 0; VerGrid[pos++] = x; VerGrid[pos++] = h;
            }
            for (short x = (short)(cx - step); x > 0; x -= step)
            {
                VerGrid[pos++] = x; VerGrid[pos++] = 0; VerGrid[pos++] = x; VerGrid[pos++] = h;
            }
            for (short y = (short)(cy + step); y < h; y += step)
            {
                VerGrid[pos++] = 0; VerGrid[pos++] = y; VerGrid[pos++] = w; VerGrid[pos++] = y;
            }
            for (short y = (short)(cy - step); y > 0; y -= step)
            {
                VerGrid[pos++] = 0; VerGrid[pos++] = y; VerGrid[pos++] = w; VerGrid[pos++] = y;
            }
            if (flag)
            {
                flag   = false;
                Spline = new cSpline(gl);
            }
        }