• Sign Up
• Login
• API
• FAQ
• Tools
• Archive
daily pastebin goal
16%
SHARE
TWEET

# helleman

a guest Nov 24th, 2017 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
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');
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top