Advertisement
_Black_Panther_

Simpson's 1/3rd Rule (Simple)

Jul 24th, 2022
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. disp("------------------------Simpson's 1/3rd 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)/2;
  16. x1 = a + h;
  17. h
  18.  
  19. % f = inline(str,'x') ;
  20. % f = str2func(['@(x) ',str]);
  21.  
  22. fa = exp(a) ;
  23. fb = exp(b) ;
  24. fx = 4* exp(x1) ;
  25. I = (h/3)*(fa+fb+fx);
  26.  
  27.  
  28. disp(['Ans: ', num2str(I)])
  29.  
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement