An Introduction To Programming Through C++
IIT Bombay.
Week 4 Quiz:
--------------------------------------------------------------------------------------------------------------------------
1.The numerical integration program discussed in the lecture estimates the area under the curve f(x) between p+iw and p+(i+1)w by f(p+iw)*w. Which of the following is true
a) The answer produced by the program will exactly equal ln(x).
b) The answer produced by the program will be larger than ln(x).
c) The answer produced by the program will be smaller than ln(x). (NOT CONFIRM)
d) The answer produced by the program may be smaller or larger than ln(x) depending upon the value of x.
2.I wish to find ln(x) given x. Which of the following is/are correct?
a) Using Taylor series will be convenient.
b) Using Bisection method will be convenient.
c) Using Newton-Raphson method will be convenient.
d) None of the 3 methods mentioned above will be convenient.
3.We wish to calculate the sine of 1.5 radians. One way (Method A) is to use Taylor series as was discussed in the lecture. Another way (Method B) is to note that sin(x) = cos(PI/2 - x). So we will instead calculate cos(PI/2 - 1.5) = cos(0.07) assuming PI=3.14.
Specifically we will use the series:
cos(y)=1−y2/2!+y4/4!−y6/6!...
With y = 0.07, which of the following is/are true (You can either expand out the series and see which terms are likely to become smaller quickly or write a program and see directly) :
a) We will get as good an answer as we want if we take sufficiently many terms in either method A or method B.
b) We will need fewer terms to get a good answer in method A than in method B.
c) We will need fewer terms to get a good answer in method B than in method A. (NOT CONFIRM)
d) We will need the same number of terms to get a good answer in method A and method B.
--------------------------------------------------------------------------------------------------------------------------
In the lectures we discussed the Newton Raphson method to find square roots. The code given was:
double y; cin >> y;
double xi=1;
while(abs(xi*xi – y) > 0.001){
xi = (xi + y/xi)/2 ;
}
cout << xi << endl;
Select from the following, the codes that are equivalent to the above.
4.// Code ..
double y; cin >> y;
for(double xi=1; abs(xi*xi – y) > 0.001; xi = (xi + y/xi)/2){}
// yes, empty body
cout << xi << endl;
a) Equivalent
b) Not Equivalent
5.// Code ..
double y; cin >> y;
double xi=1;
for( ; abs(xi*xi – y) > 0.001; xi = (xi + y/xi)/2){}
// yes, empty body
cout << xi << endl;
a) Equivalent
b) Not Equivalent.
6.// Code ..
double y; cin >> y;
double xi;
for(xi=1; abs(xi*xi – y) > 0.001; ){
xi = (xi + y/xi)/2;
}
cout << xi << endl;
a) Equivalent
b) Not Equivalent
7.// Code ..
double y; cin >> y;
double xi;
for(xi=1; ; xi = (xi + y/xi)/2){
if(abs(xi*xi – y) > 0.001) break;
}
cout << xi << endl;
a) Equivalent
b) Not Equivalent
8.I would like to find x such that x>0 and sin(x)=x/2. I decide to usethe bisection method to find the root of f(x) = x/2 - sin(x). What values will be acceptable choices for xL, xR?
You might recall that sin(pi/6) = 0.5, sin(pi/2) = 1, sin(pi) = 0, and
pi = 3.14 (approx).
a) pi/6, pi/2
b) pi/2, pi
c) -pi/2, pi/2
d) This cannot be done using the bisection method
9.I would like to find x such that x>0 and sin(x)=x/2. I decide to use
the Newton Raphson method to find the root of f(x) = x/2 - sin(x). I
start with x_0 = PI. What will x_1 be?
Write your answer to have exactly 2 decimal places.
Ans:2.07,2.11
--------------------------------------------------------------------------------------------------------------------------
Given below is a program to find the least common multiple (LCM) of two
numbers A,B by brute force search.
main_program{
int m,n; cin >> m >> n;
for(int i=blank1; i blank2 blank3; i = i blank4 1){
if((i % m == 0) && (i % n == 0)){
cout << i << endl;
break;
}
}
}
10.What is blank1? Choose the best possible answer.
a) m
b) n
c) min(m,n)
d) max(m,n)
e) m*n
11.What is blank2?
a) <
b) >
c) <=
d) >=
12.What is blank3?
a) m
b) n
c) min(m,n)
d) max(m,n)
e) m*n
13.What is blank4?
a) +
b) -
c) *
d) /
14.Suppose in the bargaining problem as discussed in the lecture, the price that the seller desires is Rs 1000. If the buyer offers Rs. 800, what should the counter offer of the seller be, assuming the rule that the average of the buyer's and sellers offers should be the
desired price?
Ans:1200
15.A tank has capacity 20 litres and initially contains 10 litres.
As discussed in the lecture, if more water is poured into it than what
can be accommodated the excess flows away and is wasted. Likewise if
more is demanded than what is in the tank, only what is in the tank
can be given. First 15 litres of water are poured. Then 15 litres
are asked to be given. Then 5 litres are poured. Then 12 litres are
demanded. How much water remains in the tank at the end?
0
Ans:0
16.Suppose I want to read in a 1000 digit number and print the result when 1 is added to it. Only using what is covered in the course so far, which of the following is true? You may assume that the digits are separated by spaces
a) It cannot be done.
b) It can be done if the digits are given least significant to most significant and need to be printed in the same order.
c) It can be done if the digits are given most significant to least significant and need to be printed in the same order.
d) It can be done if the digits are given in any order and need to be printed in the same order.
WEEK :4 PROGRAMMING ASSIGNMENT 1 SOLUTION
CLICK ON BELOW LINK.
<<CLICK HERE FOR PROGRAMMING ASSIGNMENT 1 WEEK 4>>
FOLLOW OUR WEBSITE FROM THE BUTTON PROVIDED TO THE BOTTOM OF PAGE TO GET SOON ANSWERS OF PROGRAMS.
Disclaimer: Here you can find all nptel assignment solutions related to CS stream.These may help you for your assignment.The answers are only for verification.You cannot copy these directly from the post(code of conduct of NPTEL).These is not 100% correct solutions.
No comments:
Post a Comment
If you have any problems related to solutions or any concept please let me know.