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