Recitation Problems for Matlab Week 2

Recitation Problems for Matlab Week 2 - Recitation Problems...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Recitation Problems for Matlab Week 2 Problem #1 Code examples pg 5-7 of week 2 lecture notes >> A = [1 2 3; 2 0 4; 0 8 5] A = 1 2 3 2 0 4 0 8 5 >> size(A) ans = 3 3 >> A(1,1) ans = 1 >> A(2,3) ans = 4 >> A(3,:) ans = 0 8 5 >> A = [1 2 3 4; 2 0 5 6; 0 8 7 9] A = 1 2 3 4 2 0 5 6 0 8 7 9
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
>> A' ans = 1 2 0 2 0 8 3 5 7 4 6 9 Problem #2 Code examples on pp. 19-21 of week-2 lecture notes >> N = 8; n = 1:N; >> y = cumsum(1./2.^n); >> z = 1 - 1./2.^n; >> fprintf('%d %10.8f %10.8f\n',[n; y; z]); 1 0.50000000 0.50000000 2 0.75000000 0.75000000 3 0.87500000 0.87500000 4 0.93750000 0.93750000 5 0.96875000 0.96875000 6 0.98437500 0.98437500 7 0.99218750 0.99218750 8 0.99609375 0.99609375 >> ti = A(:,2); H = A(:,3); yi = cumsum(H); >> p = polyfit(ti,yi,1) p = 1.1346 4.8846 >> t = linspace(1,20, 101); y = polyval(p,t); >> plot(t,y,'r-', ti,yi,'b.', 'markersize', 18); xlabel('\itt'); ylabel('totals'); xaxis(0,21,0:2:20); yaxis(0,800,0:100:800); grid on; title('Hank Aaron''s Home Run Output'); legend(' linear fit', ' data', 'location', 'se'); print -dmeta aaron.wmf
Background image of page 2
0 2 4 6 8 10 12 14 16 18 20 0 100 200 300 400 500 600 700 800 t totals Hank Aaron's Home Run Output      linear fit  data Problem #3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

Recitation Problems for Matlab Week 2 - Recitation Problems...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online