SHARE
TWEET

Quadrature Gauss

UtamaDonny Dec 9th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. clc
  2. clear
  3.  
  4. disp('Masukan Fungsi :')
  5. s=input(' ', 's');
  6. f=inline(s, 'x');
  7. a=input('batas kiri :');
  8. b=input('batas kanan :');
  9. OK = true;
  10.  
  11. while (OK==true);
  12.     N=input('masukan derajat N(1<N<7) :');
  13. if(N>1 && N<7)
  14.     OK=false;
  15. else
  16.     disp('masukan nilai N lagi:')
  17. end
  18. end
  19.  
  20. Tabel2=zeros(2,2);
  21. Tabel3=zeros(3,2);
  22. Tabel4=zeros(4,2);
  23. Tabel5=zeros(5,2);
  24. Tabel6=zeros(6,2);
  25. Tabel2=[0.5773502692 1.00000; -0.5773502692 1.00000];
  26. Tabel3=[0.7745966692 0.5555555556; 0.000 0.8888888889; -0.7745966692 0.5555555556];
  27. Tabel4=[0.8611363116 0.3478548451; 0.3399810436 0.6521451549; -0.8611363116 0.3478548451; -0.3399810436 0.6521451549];
  28. Tabel5=[0.9061798459 0.2369268851; 0.5384693101 0.4786286705; 0.000 0.5688888889; -0.9061798459 0.2369268851; -0.5384693101 0.4786286705];
  29. Tabel6=[0.9324695142 0.1713244924; 0.6612093864 0.3607615730; 0.2386191861 0.4679139345; -0.9324695142 0.1713244924; -0.6612093864 0.3607615730; -0.2386191861 0.4679139345];
  30.  
  31. T=zeros(N,2);
  32.  
  33. if (N==2)
  34.     T=Tabel2;
  35. else if(N==3)
  36.         T=Tabel3;
  37.     else if(N==4)
  38.             T=Tabel4;
  39.         else if(N==5)
  40.                 T=Tabel5;
  41.             else if(N==6)
  42.                     T=Tabel6;
  43.                 end
  44.             end
  45.         end
  46.     end
  47. end
  48.  
  49. t=zeros(N,1);
  50. x=zeros(N,1);
  51. c=zeros(N,1);
  52.  
  53. for i=1:N
  54.     t(i)=T(i,1);
  55.     c(i)=T(i,2);
  56. end
  57.  
  58. I=0;
  59. for i=1:N
  60.     x(i)=(b-a)*t(i)/2+(a+b)/2;
  61.     I=I+c(i)*f(x(i));
  62. end
  63.  
  64. I=(b-a)*I/2;
  65. fprintf('Hasil Integral= %12.8f\n',I);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top