Advertisement
_Black_Panther_

Trapezoid Rule (Simple)

Jul 24th, 2022
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1.  
  2. disp("------------------------Trapezoid Rule------------------------")
  3.  
  4. % str = input('Give an equation in x: ','s') ;
  5. % a = input('Enter lowerbound value:');
  6. % a
  7. % b = input('Enter upperbound value:');
  8. % b
  9.  
  10. str = "x*x*x+1"
  11. a=1;
  12. b=2;
  13. a
  14. b
  15.  
  16.  
  17. h = (b-a);
  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. I = (h/2)*(fa+fb);
  26. % disp("Value of y");
  27. % y
  28. % disp(['"' str '", for x = ' num2str(a) ', equals ' num2str(I)]) ;
  29.  
  30. disp(['Ans: ', num2str(I)])
  31.  
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement