이 튜토리얼에서는 Lagrange 공식을 사용하여 Inverse Interpolation을 구현하는 프로그램에 대해 설명합니다.
역 보간은 알 수 없는 함수에 대해 두 개의 표로 작성된 값 세트 사이에 있는 종속 값의 주어진 값에서 독립 변수 값을 찾는 방법으로 정의됩니다.
예시
#include <bits/stdc++.h>
using namespace std;
//structuring the values of x and y
struct Data {
double x, y;
};
//calculating inverse interpolation
double calc_invinter(Data d[], int n, double y){
double x = 0;
int i, j;
for (i = 0; i < n; i++) {
double xi = d[i].x;
for (j = 0; j < n; j++) {
if (j != i) {
xi = xi * (y - d[j].y) / (d[i].y - d[j].y);
}
}
x += xi;
}
return x;
}
int main(){
Data d[] = {
{ 1.27, 2.3 },
{ 2.25, 2.95 },
{ 2.5, 3.5 },
{ 3.6, 5.1 }
};
int n = 6;
double y = 4.5;
cout << "Value of x (y = 4.5) : " << calc_invinter(d, n, y) << endl;
return 0;
} 출력
Value of x (y = 4.5) : 2.51602