Facebook
From Aqua Tortoise, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 199
  1. function int_zad1
  2. a = 0;
  3. b = 3;
  4.  
  5. I_a1 = af1(b) - af1(a);
  6.  
  7. I_a2 = af2(b) - af2(a);
  8.  
  9.  
  10. I_a3 = af3(b) - af3(a);
  11.  
  12.  
  13. I_a4 = af4(b) - af4(a);
  14.  
  15.  
  16.  
  17. It = trapezoidal(@f3, a, b)
  18. error_t = abs(It - I_a3)
  19.  
  20. Ir = rectangular(@f3, a, b)
  21. error_r = abs(Ir - I_a3)
  22.  
  23. Is = Simpson(@f3, a, b)
  24. error_s = abs(Is - I_a3)
  25.  
  26. Is2 = Simpson2(@f3, a, b)
  27. error_s2 = abs(Is2 - I_a3)
  28.  
  29. end
  30. function y = f1(x)
  31.     y=x^2;
  32. end
  33.  
  34. function y = f2(x)
  35.     y= sin(x);
  36. end
  37.  
  38. function y = f3(x)
  39.     y=1/(1+25*x^2);
  40. end
  41.  
  42. function y = f4(x)
  43.     y= 1/(1+cos(x));
  44. end
  45.  
  46. function y = af1(x)
  47.     y=(1/3)*x^3;
  48. end
  49.  
  50. function y = af2(x)
  51.     y = -cos(x);
  52. end
  53.  
  54. function y = af3(x)
  55.     y=(1/5)*atan(5*x);
  56. end
  57.  
  58. function y = af4(x)
  59.     y=tan(x/2);
  60. end
  61.  
  62. function I = rectangular(f, a, b) %kwadratura lewego prostokata
  63.     I= f(a)*(a-b);
  64. end
  65. function I = trapezoidal(f, a, b)
  66.     I=((b-a)/2)*(f(a)+f(b));
  67. end
  68.  
  69. function I = Simpson(f, a, b)
  70.     I=((b-a)/6)*(f(a)+4*f(a +(b-a)/2)+f(b));
  71. end
  72.  
  73. function I = Simpson2(f, a, b)
  74.     I=((b-a)/8)*(f(a)+3*f(a +(b-a)/3)+ 3*f(a+2*(a-b)/3)+f(b));
  75. end