Advertisement
hiddenGem

Double Integral Using Riemann Sums

Oct 22nd, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.73 KB | None | 0 0
  1. %% Double Integral using Riemann Sums
  2. % READ THROUGH EVERYTHING
  3.  
  4. % Using Reimann sum S#,# to estimate the double integral of *function* over R =
  5. % [matrix1] x [matrix2] using regular partition and upper-right vertices
  6. % of the sub-rectangles as sample points.
  7.  
  8. % USED FOR f(x,y) = #xy
  9.  
  10. S = input('Riemann sum divisions');
  11. R1 = input('matrix 1 in brackets');
  12. R2 = input('matrix 2 in brackets');
  13. delta_x = (R1(2)-R1(1))/S(1);
  14. delta_y = (R2(2)-R2(1))/S(2);
  15. delta_A = delta_x * delta_y;
  16. a = R1(1):delta_x:R1(2);
  17. b = R2(1):delta_y:R2(2);
  18.  
  19. sum = 0;
  20.  for j = 2:length(b);
  21.     for i = 2:length(a);
  22.         c = a(i)*b(j);
  23.         sum  = sum + c;
  24.     end
  25. end
  26.  
  27. sum*delta_A
  28.  
  29. %  ANSWER IS sum*delta_A* # from the f(x,y) function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement