Advertisement
Guest User

Area under weird curve

a guest
Jun 13th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.60 KB | None | 0 0
  1. %% Parametrization of curve
  2. x = @(t) sin(t) + cos(t).*(pi-t);
  3. y = @(t) -cos(t)+sin(t).*(pi-t);
  4.  
  5. thetas = linspace(0, pi, 10000);
  6.  
  7. curve.xi = x(thetas);
  8. curve.yi = y(thetas);
  9.  
  10. circle.xi = sin(thetas);
  11. circle.yi = cos(thetas);
  12.  
  13. %% Nice plot
  14. figure(1)
  15. clf
  16. grid
  17. hold on
  18. plot(curve.xi, curve.yi, 'b.')
  19. plot(circle.xi, circle.yi, 'y.')
  20.  
  21. %% Calculate area below blue curve
  22. integral = 0;
  23. for i = 2:numel(curve.yi)
  24.     delta = abs(curve.xi(i)-curve.xi(i-1));
  25.     integral = integral + delta*curve.yi(i);
  26. end
  27.  
  28. % Total should be:
  29. total = 2*(integral-pi/2) + pi^3/2;
  30. disp(['Total = ' num2str(total)])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement