Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <iomanip>
- #include <fstream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- void interpolacja(double x, int ilosc, double *tab, double *tab1)
- {
- double *l = new double[ilosc];
- for (int i = 0; i < ilosc; i++)
- {
- if (i == ilosc-2)
- {
- l[i] = ((x - tab[i + 1]) / (tab[i] - tab[i + 1]))*((x - tab[0]) / (tab[i ] - tab[0]));
- }
- else if (i == ilosc - 1)
- {
- l[i] = ((x - tab[0]) / (tab[i] - tab[0]))*((x - tab[1]) / (tab[i] - tab[1]));
- }
- else
- {
- l[i] = ((x - tab[i + 1]) / (tab[i] - tab[i + 1]))*((x - tab[i + 2]) / (tab[i] - tab[i + 2]));
- }
- }
- double L = 0;
- for (int i = 0; i < ilosc; i++)
- {
- L = L + (tab1[i] * l[i]);
- }
- cout <<"L(x) = "<< L << endl;;
- }
- int main()
- {
- cout << "Wprowadz dla jakiej wartosci znalezc interpolacje: ";
- double x;
- cin >> x;
- int ilosc = 3;
- double *tab = new double[ilosc];
- double *tab1 = new double[ilosc];
- tab[0] = 1;
- tab[1] = 3;
- tab[2] = 5;
- tab1[0] = 12;
- tab1[1] = 4;
- tab1[2] = 4;
- interpolacja(x, ilosc, tab, tab1);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement