Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <sstream>
- #include <iomanip>
- using namespace std;
- void wczytaj_dane(float *xi, float *fi, int n)
- {
- cout << "Podaj wezly w ciaglu rosnacym" << endl;
- cout << "podaj wezel nr" << 0 <<endl;
- cin >> xi[0];
- for(int i = 1; i <= n-1; i++)
- {
- cout << "podaj wezel nr" << i <<endl;
- cin >> xi[i];
- while (xi[i-1] >= xi[i])
- {
- cout << "Wezel jest mniejszy lub rowny poprzedniego" <<endl;
- cin >> xi[i];
- }
- }
- cout << "Podaj fi" << endl;
- for(int i = 0; i <= n-1; i++)
- {
- cout << "podaj f1 nr" << i <<endl;
- cin >> fi[i];
- }
- }
- float wielomian_newtona(float *xi, float *fi, int n)
- {
- float *l = new float[n];
- float xp;
- int od=1;
- int zm=0;
- int k=n-1;
- float wynik = 0;
- cout << "Podaj punkt interpolacji" <<endl;
- cin >> xp;
- while(xp < xi[0] || xp > xi[n])
- {
- cout << "Punkt nie zawiera sie w przedziale interpolacji" << endl << endl << "Wprowadz nowe xp" <<endl;
- cin >> xp;
- }
- for(int j=0;j<n-1;j++)
- {
- for(int i=k;i>zm;i--)
- {
- fi[i]= (fi[i] - fi[i-od]) /(xi[i] - xi[i-od]);
- }
- od+=1;
- k-=1;
- zm+=1;
- for(int z=0;z<n;z++)cout<<setw(8)<< xi[z] <<setw(8) << fi[z] << setw(8)<<endl;
- cout <<endl<<endl;
- }
- }
- int main()
- {
- int n;
- cout << "Podaj stopien wielomianu" << endl;
- cin >> n;
- float *xi = new float[n];
- float *fi = new float[n];
- wczytaj_dane(xi, fi, n);
- cout<<endl<<"Wprowadzone dane: "<<endl;
- for(int i=0;i<n;i++)
- {
- cout<<setw(8)<< xi[i] <<setw(8) << fi[i] << setw(8)<<endl;
- }
- wielomian_newtona(xi, fi, n);
- cout <<endl;
- for(int i=0;i<n;i++)cout<<setw(8)<< xi[i] <<setw(8) << fi[i] << setw(8)<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement