madzik4113

grupa3 moja edycja

Mar 10th, 2014
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <math.h>
  4.  
  5. using namespace std;
  6.  
  7. int _tmain(int argc, _TCHAR* argv[])
  8. {
  9. int wybor;
  10. cout<<"Podaj metode: "<<endl;
  11. cout<<"1) Metoda Lagrange'a "<<endl;
  12. cout<<"2) Metoda Hermite'a "<<endl;
  13. cout<<"0) Zamknij program" <<endl;
  14. cin>>wybor;
  15. switch (wybor)
  16. {
  17. case 0:
  18. { system("pause");
  19. return 0;
  20. }
  21. case 1:
  22. {
  23. int n;
  24. double *A;
  25. double *w;
  26. double x;
  27. cout<<"Metoda Lagrange'a"<<endl;
  28. cout<<"podaj rozmiar tablicy wezlow : ";
  29. cin>>n;
  30. A=new double[n];
  31. w=new double[n];
  32. for(int i=0;i<n;i++)
  33. {
  34. cout<<"podaj wartosc tablicy wezlow ["<<i<<"] = ";
  35. cin>>A[i];
  36. }
  37. for(int i=0;i<n;i++)
  38. {
  39. cout<<"podaj wartosci w wezlach ["<<i<<"] = ";
  40. cin>>w[i];
  41. }
  42.  
  43.  
  44. cout<<"Podaj x: ";
  45. cin>>x;
  46. double s=0;
  47. double w1=1;
  48. double w2=1;
  49.  
  50. for (int j=0; j<n-1; j++) {
  51. for ( int i = 0; i<n-1; i++)
  52. {
  53. if (i!=j){
  54. w1=w1*(x-A[i]);
  55. w2=w2*(A[j]-A[i]);}
  56. }
  57. s=s+((w[j]*w1)/w2);
  58. }
  59. cout<<"wynik: "<<s;
  60. break;
  61. }
  62. case 2:
  63. {
  64. cout<<"Hr";
  65. break;
  66. }
  67. default:
  68. cout<<"Nie znany znak";
  69. break;
  70. }
  71. system("pause");
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment