0% found this document useful (0 votes)
52 views

Interpolare Liniara

This document contains code for linear interpolation in C++. It defines arrays to store temperature and value data read from a file. It includes functions to read the data file, perform linear interpolation between data points, and loop to allow the user to enter temperatures and get interpolated values. The main function calls the read and interpolation functions, prompting the user for a temperature and returning the interpolated value at that point.

Uploaded by

Barosz
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Interpolare Liniara

This document contains code for linear interpolation in C++. It defines arrays to store temperature and value data read from a file. It includes functions to read the data file, perform linear interpolation between data points, and loop to allow the user to enter temperatures and get interpolated values. The main function calls the read and interpolation functions, prompting the user for a temperature and returning the interpolated value at that point.

Uploaded by

Barosz
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

//interpolare liniara

#include<stdio.h>
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
float sir[100],tprf[100],tve[100],ax[100];
float txprf,txve;
int n,i;

void citfis(float a1[100],float a2[100])


{
ifstream citire("tprf.dat",ios::in);
i=0;
while (citire.eof()==0)
{
i++;
citire>>a1[i]>>a2[i]; break;
//case 3: citire>>a1[i]>>a2[i]>>a3[i]; break;
//case 4: citire>>a1[i]>>a2[i]>>a3[i]>>a4[i]; break;
//case 5: citire>>a1[i]>>a2[i]>>a3[i]>>a4[i]>>a5[i]; break;
//default: cout<<"s-a depasit numarul de coloane admise!";
}
}
citire.close();
}

float interlin(int n, float x[100],float fx[100], float arg)

{
int

i;

float a0,a1,val;
if (arg < x[1])
{
val=fx[1];
}
if (arg > x[n])
{
val=fx[n];
}

for (i=1;i<=n-1;i++)
if ((arg>= x[i]) & (arg<= x[i+1]))
{
a1=(fx[i+1]-fx[i])/(x[i+1]-x[i]);
a0=fx[i]-(fx[i+1]-fx[i])/(x[i+1]-x[i])*x[i];
val=a0+a1*arg;
}
return val;
}

void main()
{
char car;
clrscr();

citfis(tprf,tve);
car=' ';
while (car!='n')
{
cout<<" \n Temperatura PRF :"<<txprf;
txve=interlin(n,tprf,tve,txprf);
//cout<<"T Prf " <<T
}
getch();
}

You might also like