Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. double silnia(double n)
  6. {
  7. int Silnia=1;
  8.  
  9. for (int i=n;i>0;i--)
  10. Silnia*=i;
  11.  
  12. return Silnia;
  13. }
  14.  
  15. void Hermit(int n,double *x,double *kx,double *y, double *a)
  16. {
  17.  
  18. double * r = new double[n+1];
  19. double pom;
  20. int indeks;
  21. for(int i=0; i<=n; i++){if (kx[i]==0)
  22. {r[i] = y[i]; pom= y[i];indeks = i;
  23. } //pierwsze wystąpienie węzła
  24. else
  25. r[i]=pom; //kolejny ten samfor
  26. for(int k=i-1; k>=0; k--)
  27. {if (x[i]!=x[k])r[k]=(r[k+1]-r[k])/(x[i]-x[k]);
  28. else
  29. r[k]=y[indeks+i-k]/silnia(kx[indeks+i-k]);}
  30. a[i]=r[0];
  31. }
  32. }
  33.  
  34.  
  35. void countVector(double n,double x, double *kx)
  36. {
  37.  
  38. kx[0]=0;for(int i=1; i<=n; i++)if (x[i]==x[i-1])kx[i] = kx[i-1]+1;
  39. else kx[i] = 0;
  40.  
  41. }
  42.  
  43. int main()
  44. {
  45. int n;
  46. cout<<"Podaj stopien wielomianu"<<endl;
  47. cin>>n;
  48. if (n<=0)
  49. {
  50. cerr<<"Stopien musi być dodatni"<<endl;
  51. return 0;}
  52.  
  53. else
  54.  
  55. {
  56. double *x=new double[n+1];
  57. double *f=new double[n+1];
  58. double *firstDerivate=new double[n+1];
  59.  
  60.  
  61.  
  62.  
  63. for (int i=0; i<n+1;i++)
  64. {
  65. cout<<" Podaj " << i <<" wspolrzedna wielomianu"<<endl;
  66. cin>>x[i];
  67. cout<<" Podaj f[i]" <<endl;
  68. cin>>f[i];
  69. cout<<"Podaj pochodna"<<endl;
  70. cin>>firstDerivate[i];
  71. }
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78. for (int i=1; i<n+1; i++)
  79. {
  80. if (x[i-1]>=x[i])
  81. {cout<<"Nieposortowane dane"<<endl;
  82. return -1;
  83. }
  84. }
  85.  
  86.  
  87.  
  88. double xp;
  89.  
  90. cout<<"Podaj xp"<<endl;
  91. cin>>xp;
  92.  
  93. Hermit(n,x,f,)
  94.  
  95. /* if (xp<x[0] || xp>x[n-1])
  96. {cerr<<"Wspolrzedna nie nalezy do przedziału"<<endl;
  97. return -1;}
  98. */
  99. // cout<<"Wynik"<<counting_interpolation(n,xp,x,f);
  100.  
  101. }
  102.  
  103. return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement