This preview shows pages 1–2. Sign up to view the full content.
14:440:127 Introduction to Computers for Engineers
Problems for students to attempt in Recitation 7
1)
Use a 'for loop' to calculate the sum of all prime numbers from 1000 to 2000.
2)
Use a 'while loop' to calculate the sum of all prime numbers from 1000 to 2000.
3)
What sequence of numbers will be displayed by the following ‘for loop’?
n = 10;
for j = 1:n
n = n1
j
end
4)
Define values for three variables of your choosing.
Write an anonymous function that
switches the values of variables one and two and another that does so for variables two
and three.
5)
Write a program to plot the curve y=sin(x)+cos(x) within [0,2
π
].
a) use fplot and a normal userdefined function.
b) use fplot with an anonymous function that defines y.
6)
The
Fibonacci numbers
are a sequence of numbers and defined as,
The first number of the sequence is 0, the second number is 1, and each subsequent
number is equal to the sum of the previous two numbers of the sequence itself.
Use a ‘for’ loop to calculate the 100
th
number F
100
.
7)
Use a ‘while’ loop to find the first
Fibonacci number
larger than 10,000.
Then, try
writing this as a ‘for’ loop (using break).
8)
Create a 15 by 15 matrix of all one value (your choice), then write a nested ‘for loop’
that changes the 5 by 5 range of numbers (represented by shaded areas) in each of the
corners to another value (your choice).
9)
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.
This note was uploaded on 02/29/2012 for the course 440 127 taught by Professor Blase during the Fall '09 term at Rutgers.
 Fall '09
 blase

Click to edit the document details