xsobolx

gauss

Jun 28th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. double calka(float);
  5. double metoda_Gaussa(double, double, double*, double*, double(float));
  6.  
  7. void main(void)
  8. {
  9. double xx[10] =
  10. { 0.2955242247147529,
  11. 0.2955242247147529,
  12. 0.2692667193099963,
  13. 0.2692667193099963,
  14. 0.2190863625159820,
  15. 0.2190863625159820,
  16. 0.1494513491505806,
  17. 0.1494513491505806,
  18. 0.0666713443086881,
  19. 0.0666713443086881
  20. };
  21.  
  22. double xy[10] =
  23. { -0.1488743389816312,
  24. 0.1488743389816312,
  25. -0.4333953941292472,
  26. 0.4333953941292472,
  27. -0.6794095682990244,
  28. 0.6794095682990244,
  29. -0.8650633666889845,
  30. 0.8650633666889845,
  31. -0.9739065285171717,
  32. 0.9739065285171717
  33. };
  34.  
  35. printf("Wynik: %f\n", metoda_Gaussa(1, 2, xx, xy, calka));
  36. }
  37.  
  38. double calka(float x)
  39. {
  40. return 1/log(x+1);
  41. }
  42. double metoda_Gaussa(double poczatek, double koniec, double *xx, double *xy, double wzor(float))
  43. {
  44. double out = 0, srednia = (koniec - poczatek) / 2;
  45. int i=0;
  46. for (i; i<10;){
  47. out += xx[i] * wzor(((poczatek+koniec)/2)+ srednia * xy[i]);
  48. i++;
  49. }
  50.  
  51. return out*srednia;
  52. }
Add Comment
Please, Sign In to add comment