Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. //Integrala Richardson
  2. #include <iostream>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. float f(float x)
  7. {
  8. return x*exp(x*x);
  9. }
  10.  
  11. float rick (float ls, float ld, int n, int m)
  12. {
  13. float h, k, sumh, sumk, sum;
  14. int i;
  15. h=(ld-ls)/n;
  16. k=(ld-ls)/m;
  17. sumh=(f(ls)+f(ld))/2*h;
  18. sumk=(f(ls)+f(ld))/2*k;
  19. for(i=1;i<=n-1;i++) sumh+=h*f(ls+i*h);
  20. for(i=1;i<=m-1;i++) sumk+=k*f(ls+i*k);
  21. sum=sumh+(sumh-sumk)/((k/h)*(k/h)-1);
  22. return sum;
  23. }
  24.  
  25. int main() {
  26. cout<<rick(2.1, 3.2, 1000, 1200);
  27. }
  28.  
  29.  
  30.  
  31. //derivata
  32. #include <iostream>
  33. #include <cmath>
  34. using namespace std;
  35. float f (float x){return exp(x);
  36. }
  37. float d2p(float x0, float h)
  38. {
  39. return (f(x0+h/2)-f(x0-h/2))/h;
  40. }
  41. int main ()
  42. {
  43. float x0=0, h=1e-4;
  44. cout<<d2p(x0, h);
  45. }
  46.  
  47.  
  48.  
  49. //Integrala Simpson
  50. #include <iostream>
  51. #include <cmath>
  52. using namespace std;
  53.  
  54. float f(float x)
  55. {
  56. return x*exp(x*x);
  57. }
  58.  
  59. float simpson (float ls, float ld, int n)
  60. {
  61. float h, sum;
  62. int i;
  63. h=(ld-ls)/n;
  64. sum=h*((f(ls)+f(ld))/3);
  65. for(i=1;i<=n-1;i++)
  66. {
  67. if(i%2==0)sum+=2*h*f(ls+i*h)/3;
  68. else sum+=4*h*f(ls+i*h)/3;
  69. }
  70. return sum;
  71. }
  72.  
  73. int main() {
  74. cout<<simpson(2.1, 3.2, 1000);
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement