hw1_solution_2008

hw1_solution_2008 - if sum>5280 %check if the...

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

View Full Document Right Arrow Icon
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
Background image of page 3

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

View Full DocumentRight Arrow Icon
Background image of page 4
Background image of page 5

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

View Full DocumentRight Arrow Icon
Background image of page 6
Background image of page 7

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

View Full DocumentRight Arrow Icon
Background image of page 8
Background image of page 9

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

View Full DocumentRight Arrow Icon
Background image of page 10
PROBLEM 5 There are two variations of the code which can be used for this problem. It is important to look at both for learning and having fun at the same time. CODE 1 sum=0; n=0; while (sum<5280) n=n+1; sum=sum+n^2; end disp([ 'The sum of series exceeds 5280 at n=' ,num2str(n)]); disp([ 'The final sum for n=' ,num2str(n), ' is ' ,num2str(sum)]); CODE 2 sum=0; n=0; for i=1:100 n=n+1; sum=sum+n^2;
Background image of page 11

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

View Full DocumentRight Arrow Icon
Background image of page 12
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if sum&gt;5280 %check if the sum has exceeded 5280 break %if the sum has exceeded 5280, break the while loop end end disp([ 'The sum of series exceeds 5280 at n=' ,num2str(n)]); disp([ 'The final sum for n=' ,num2str(n), ' is ' ,num2str(sum)]); OUTPUT The OUTPUTs of these two codes are the same and shown below The sum of series exceeds 5280 at n=25 The final sum for n=25 is 5525...
View Full Document

Page1 / 12

hw1_solution_2008 - if sum&amp;amp;gt;5280 %check if the...

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

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