Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- double silnia(double n)
- {
- int Silnia=1;
- for (int i=n;i>0;i--)
- Silnia*=i;
- return Silnia;
- }
- void Hermit(int n,double *x,double *kx,double *y, double *a)
- {
- double * r = new double[n+1];
- double pom;
- int indeks;
- for(int i=0; i<=n; i++){if (kx[i]==0)
- {r[i] = y[i]; pom= y[i];indeks = i;
- } //pierwsze wystąpienie węzła
- else
- r[i]=pom; //kolejny ten samfor
- for(int k=i-1; k>=0; k--)
- {if (x[i]!=x[k])r[k]=(r[k+1]-r[k])/(x[i]-x[k]);
- else
- r[k]=y[indeks+i-k]/silnia(kx[indeks+i-k]);}
- a[i]=r[0];
- }
- }
- void countVector(double n,double x, double *kx)
- {
- kx[0]=0;for(int i=1; i<=n; i++)if (x[i]==x[i-1])kx[i] = kx[i-1]+1;
- else kx[i] = 0;
- }
- int main()
- {
- int n;
- cout<<"Podaj stopien wielomianu"<<endl;
- cin>>n;
- if (n<=0)
- {
- cerr<<"Stopien musi być dodatni"<<endl;
- return 0;}
- else
- {
- double *x=new double[n+1];
- double *f=new double[n+1];
- double *firstDerivate=new double[n+1];
- for (int i=0; i<n+1;i++)
- {
- cout<<" Podaj " << i <<" wspolrzedna wielomianu"<<endl;
- cin>>x[i];
- cout<<" Podaj f[i]" <<endl;
- cin>>f[i];
- cout<<"Podaj pochodna"<<endl;
- cin>>firstDerivate[i];
- }
- for (int i=1; i<n+1; i++)
- {
- if (x[i-1]>=x[i])
- {cout<<"Nieposortowane dane"<<endl;
- return -1;
- }
- }
- double xp;
- cout<<"Podaj xp"<<endl;
- cin>>xp;
- Hermit(n,x,f,)
- /* if (xp<x[0] || xp>x[n-1])
- {cerr<<"Wspolrzedna nie nalezy do przedziału"<<endl;
- return -1;}
- */
- // cout<<"Wynik"<<counting_interpolation(n,xp,x,f);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement