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

Implementation the java algorithm using VHDL input ... x - the abscissa at which

ID: 1845637 • Letter: I

Question

Implementation the java  algorithm using VHDL


input ...

x   - the abscissa at which the linear interpolation is to be evaluated

xi[]- the arrays of data abscissas

yi[]- the arrays of data ordinates

imax- size of the arrays xi[] and yi[]


output ...

y    - interpolated value

====================================================================

*/

{

    double y;

    int j;

// if x is ouside the xi[] interval take a boundary value (left or right)

    if (x <= xi[0])      return y = yi[0];

    if (x >= xi[imax-1]) return y = yi[imax-1];    

// loop to find j so that x[j-1] < x < x[j]

    j = 0;

    while (j <= imax-1)

    {

     if (xi[j] >= x) break;

     j = j + 1;

     }

    y = yi[j-1] + (yi[j] - yi[j-1])*(x - xi[j-1])/(xi[j]-xi[j-1]);

    return y;

}

Explanation / Answer

#include <iostream>

#include <iomanip>

#include <cmath>

using namespace std;

double interp_1(double, double[], double[], int); //function prototype

int main ()

{

const int isize = 5; //size of arra for interpolation

double xi[isize] = {1.0, 2.0, 3.0, 4.0, 5.0}; // given xi points

double yi[isize] = {2.0, 3.0, 4.0, 5.0, 1.0}; // given yi points


cout.setf(ios::fixed | ios::showpoint);

cout.precision(5);


x = 3.2, //we are looking for linear interpolation for this x


y = interp_1(x, xi, yi, isize); //call for linear interpolation


cout << "x = " << x << "y = " << << end1;

system ("pause");

return 0;

}

double interp_1(double x, double xi[], double yi[], int imax)