14:440:127- Introduction to Computers for Engineers
Problems for students to attempt in Recitation 7- Solutions
Use a 'for loop' to calculate the sum of all prime numbers from 1000 to 2000.
s = 0;
Use a 'while loop' to calculate the sum of all prime numbers from 1000 to 2000.
s = 0;
What sequence of numbers will be displayed by the following ‘for loop’?
n = 10;
for j = 1:n
n = n-1
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
switcheroo12 = @(x,y,z) deal(y,x,z)
switcheroo23 = @(x,y,z) deal(x,z,y)
(Note… this wasn’t a very good question since you needed to use the deal( ) function,
which you haven’t seen before
Write a program to plot the curve y=sin(x)+cos(x) within [0,2
a) use fplot and a normal user-defined function.
[In the mfile myfunc.m]
y = myfunc(x)
[In the workspace]