hw1_solution_2008

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

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

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document

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

View Full Document
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;

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if sum>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

{[ snackBarMessage ]}

### Page1 / 12

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

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

View Full Document
Ask a homework question - tutors are online