"C" Program Source Code Example Using Spline Curve Fit Algorithm

  • Return to Main Menu
  • /* FILE NAME: example.c */

    /* DESCRIPTION: This "C" program demonstrates the use of a algorithm developed using results of spline curve fit program SplineCurvFit. */

    #include "stdio.h"
    #include "math.h"

    main ()
    {

    /* Coefficients from output data file (coeff_out) of spline curve fit program. */
    /* Coefficients for polynomial form equation y = f(x,z) */
    /* 4th order for x and z variation */

    double coeff1[16] = {
    3.000000e+000, 1.156667e+000, -1.175000e-002, 4.583333e-005, 2.811667e+000,
    -1.126667e-001, 1.322917e-003, -4.895833e-006, -3.525000e-002, 1.445833e-003,
    -1.734375e-005, 6.510417e-008, -1.416667e-004, 3.541667e-006, -3.385417e-008,
    1.302083e-010};

    double xval; /* Value of independent variable x */
    double yval; /* Value of dependent variable y */
    double zval; /* Value of independent variable z */
    unsigned char ans; /* Answer to query */

    ans = 'y';

    while((ans == 'y') || (ans == 'Y')) {

    printf ("INPUT INDEPENDANT VARIABLE (xval) = ");
    scanf ("%lf", &xval);
    printf ("INPUT INDEPENDANT VARIABLE (zval) = ");
    scanf ("%lf", &zval);

    /* Algorithm for polynomial form equation y = f(x,z) */
    /* 4th order for x and z variation */

    yval = coeff1[0] + coeff1[1] * zval + coeff1[2] * pow(zval, 2.0) + coeff1[3] * pow(zval, 3.0) + (coeff1[4] + coeff1[5] * zval + coeff1[6] * pow(zval, 2.0) + coeff1[7] * pow(zval, 3.0)) * xval + (coeff1[8] + coeff1[9] * zval + coeff1[10] * pow(zval, 2.0) + coeff1[11] * pow(zval, 3.0)) *
    pow(xval, 2.0) + (coeff1[12] + coeff1[13] * zval + coeff1[14] * pow(zval, 2.0) + coeff1[15] *
    pow(zval, 3.0)) * pow(xval, 3.0);

    printf ("VALUE OF DEPENDENT VARIABLE (yval) = %e\n", yval);

    printf ("TO CHECK ADDITIONAL POINTS INPUT y (yes) or n (no) ?");
    scanf ("%s", &ans);

    }
    return 0;
    } 1