Advertisement
_Black_Panther_

Simpson's 3/8th Rule (Simple)

Jul 24th, 2022
2,823
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Octave 0.51 KB | None | 0 0
  1. disp("------------------------Simpson's 3/8th Rule------------------------")
  2.  
  3. % str = input('Give an equation in x: ','s')  ;
  4. % a = input('Enter lowerbound value:');
  5. % a
  6. % b = input('Enter upperbound value:');
  7. % b
  8.  
  9. str = "exp(1)"
  10. a=-1;
  11. b=1;
  12. a
  13. b
  14.  
  15. h = (b-a)/3;
  16. x1 = a + h;
  17. x2 = a + h + h;
  18. h
  19.    
  20. % f = inline(str,'x') ;
  21. f = str2func(['@(x) ',str]);
  22.  
  23. fa = feval(f,a) ;
  24. fb = feval(f,b) ;
  25. fx1 = 3* feval(f, x1) ;
  26. fx2 = 3* feval(f, x2) ;
  27.  
  28.  
  29. I = (h/2)*(fa+fx1+fx2+fb);
  30.  
  31.  
  32. disp(['Ans: ', num2str(I)])
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement