Advertisement
Guest User

simpson integral numanlysis cw q2

a guest
Feb 11th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.40 KB | None | 0 0
  1. clear
  2. clc
  3.  
  4. disp('f(x)=ln(x)/x, x=[1,8]')
  5. q=input('Step number (must be even): ');
  6. a=input('Lower bound: ');
  7. b=input('Upper bound: ');
  8.  
  9.  
  10. for n=2:2:q
  11.     h=(b-a)/n;
  12.        
  13.    
  14.    
  15.     for i=1:(n+1)
  16.         x(i)=a+h*(i-1);
  17.         f(i)=log(x(i))/x(i);
  18.     end  
  19.    
  20.     m=(h/3)*(f(1)+f(n+1)+4*(sum(f(2:2:n-1)))+2*(sum(f(3:2:n))));
  21.  
  22.    
  23.     s(n)=m;
  24.    
  25. end
  26. plot(2:2:q,s(2:2:q))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement