Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose we are given a set of tabulated values for y versus x, i.e., y_0 y_1 y_2

ID: 3838592 • Letter: S

Question

Suppose we are given a set of tabulated values for y versus x, i.e., y_0 y_1 y_2...y_n x_0 x_1 x_2...x_n and we wish to obtain a value of y at some specified value of x that lies between two of the tabulated values. This problem is commonly solved by interpolation, i.e., by passing a polynomial y(x) through n points such that y(x_0) = y_0, y(x_1) = y_1, ...y(x_n) = y_n and then evaluating y at the desired value of x. A common way to carry out the interpolation is to use the Lagrange form of the interpolation polynomial. To do this we write y(x) = f_0(x) y_0 + f_1(x) y_1 + ... + f_n (x) y_n where f_i (x) is a polynomial such that f_i(x) = [(x - x_0) (x - x_1) ...(x - x_i) (x - x_i+1)...(x - x_n)/(x_i - x_0) (x_i - x_1) ... (x_i - x_i-1) (x_i - x_i+1)...(x_i - x_n)] Notice that f(x) = 1 and f_i (x_j) = 0, where x_j is a tabulated value of x different from x_i Therefore we are assured that y(x_i) = y_i Write a C program to read in n pairs of data, where n docs not exceed 10, and then obtain an interpolated value of y at one or more specified values of x. Use the program to obtain interpolated values of y at x = 13.7, x = 37.2, x = 112 and x = 147 from the data listed below. Determine how many tabulated pairs of data are required in each calculation in order to obtain reasonably accurate interpolated y-values.

Explanation / Answer

C PROGRAM FOR INTERPOLATION POLYNOMIAL TO PREDICT THE GIVEN VALUES:

#include<stdio.h>

main()

{

    float x[100],y[100],a,s=1,t=1,k=0;

    int n,i,j,d=1;

    printf(" Enter the number of the terms of the table: ");

    scanf("%d",&n);

    printf(" Enter the respective values of the variables x and y: ");

    for(i=0; i<n; i++)

    {

        scanf ("%f",&x[i]);

        scanf("%f",&y[i]);

    }

    printf(" The table you entered is as follows : ");

    for(i=0; i<n; i++)

    {

        printf("%0.3f %0.3f",x[i],y[i]);

        printf(" ");

    }

    while(d==1)

    {

        printf(" Enter the value of the x to find the respective value of y ");

        scanf("%f",&a);

        for(i=0; i<n; i++)

        {

            s=1;

            t=1;

            for(j=0; j<n; j++)

            {

                if(j!=i)

                {

                    s=s*(a-x[j]);

                    t=t*(x[i]-x[j]);

                }

            }

            k=k+((s/t)*y[i]);

        }

        printf(" The respective value of the variable y is: %f",k);

        printf(" Do you want to continue? Press 1 to continue and any other key to exit");

        scanf("%d",&d);

    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote