Advertisement
Guest User

helleman

a guest
Nov 24th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. fprintf('Question #3:\n');
  2. t = [1 2 3.25 4.5 6 7 8 8.5 9.3 10]; %time (s)
  3. v = [5 6 6.6 7 8.5 8 6 7 7 5]; %speed (m/s)
  4. d = trapz(t,v); %distance traveled from t = 1 to t = 10
  5. fprintf('Using the trapezoidal rule:\n\t%2.4f m are covered from t = 1s to t = 10s\n',d);
  6. pC = polyfit(t,v,3); %coefficients of cubic fit for v vs t
  7. fC = @(x) polyval(pC,x);
  8. tC = [1 5.5 10];
  9. vC = polyval(pC,tC);
  10. ISimpson = (4.5/3)*(vC(1)+4*vC(2)+vC(3));
  11. fprintf('Using Simpson''s 1/3 rule:\n\t%2.4f m are covered from t = 1s to t = 10s\n',ISimpson);
  12. IClassic = integral(fC,1,10);
  13. fprintf('Using classical integration techniques:\n\t%2.4f m are covered from t = 1s to t = 10s\n',IClassic);
  14. fprintf('Simpson''S 1/3 rule and classical integration techniques produce identical results\n');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement