
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Assignment; Class: Introduction to Computing Using MATLAB; Subject: Computer Science; University: Cornell University; Term: Spring 2009;
Typology: Assignments
1 / 1
This page cannot be seen from the preview
Don't miss anything!

CS1112 Section Exercise 3
[Last week’s challenge question] Write a script using nested conditional statements without elseif to determine in which quadrant a user-input value of A degrees belongs. Assume that the user may enter any non-negative number. For example, 725◦^ is the same, and should be treated, as 5◦. (Hint: the function rem that you saw last week might be useful.) To avoid ambiguity, we use the following convention:
Quadrant is
1 if 0 ≤ A < 90 2 if 90 ≤ A < 180 3 if 180 ≤ A < 270 4 if 270 ≤ A < 360
The following program reads an integer k and outputs all the multiples of k up to 1000. Fill in the blank.
k = input(’Please enter a positive integer smaller than 1000: ’);
for j = ______________________ fprintf(’%d ’, j); end fprintf(’\n’);
[Modified from Insight Exercise P2.1.5] For large n,
Tn = 1 +^1 22
n^2
∑^ n
k=
k^2 ≈ π
2 6
Rn = 1 − 13 + · · · − (−1)n+ 2 n − 1 =
∑^ n
k=
(−1)k+ 2 k − 1 ≈ π 4
giving two different ways to estimate π:
τn =
6 Tn ρn = 4 Rn
Write a script that displays the value of |π − ρn| and |π − τn| for n = 100 : 100 : 1000 in one table.
Write a script to print all the numbers between 1 and n, exclusive, that divide n (without a remainder using integer division). n is a user input positive integer. (Hint: Remember function rem?)
Optional Challenge Question
Refer to Question 4 and write a script to print the prime numbers that divide n. Do not use any built-in functions other than rem.