C++ Program to implement Linear Extrapolation

In this tutorial, we will be discussing a program to implement Linear Extrapolation.

Extrapolation is defined as a process in which the required value for a certain function is beyond the lower or the upper limits of the function definition.

In the case of Linear Extrapolation, the value beyond the scope is found using the tangent made on the graph of the function to determine the required value. Linear Extrapolation gives quite accurate results when applied.


#include <bits/stdc++.h>
using namespace std;
//structuring the values of x and y
struct Data {
   double x, y;
//calculating the linear extrapolation
double calc_extrapolate(Data d[], double x){
   double y;
   y = d[0].y
      + (x - d[0].x)
      / (d[1].x - d[0].x)
         * (d[1].y - d[0].y);
   return y;
int main(){
   Data d[] = { { 1.2, 2.7 }, { 1.4, 3.1 } };
   double x = 2.1;
   cout << "Value of y (x = 2.1) : " << calc_extrapolate(d, x) << endl;
   return 0;


Value of y (x = 2.1) : 4.5

Updated on: 03-Dec-2019


Kickstart Your Career

Get certified by completing the course

Get Started