APPLIED NUMERICAL METHODS WITH
PYTHON FOR ENGINEERS AND SCIENTISTS
COMPREHENSIVE TEST PAPER QUESTIONS
AND SOLUTIONS GRADED APLUS
●● Which of the following are approximations to derivatives?
Answer: All of the other responses are correct.
( f(x+h) - f(x) ) / h
( f(x) - f(x-h) ) / h
( f(x+h) - f(x-h) ) / h
●● When would you use Monte Carlo sampling methods to calculate an
integral?
Answer: When you can't use a numerical method that approximates the
area under the curve.
●● Suppose you called fmin with cos(x), x0 = 2pi + pi/4. What value
would fmin return for x, f(x)?
Answer: x=3pi, f(x)=-1.
, ●● If a function passed to fmin has more than one local minima, what
will fmin return?
Answer: One near the x0 given to fmin.
●● What does the parameter xtol control?
Answer: Stop when the differences between the parameters are smaller
than xtol.
●● Suppose your function was f(x) = 3x + 3, and you passed in x = 1.
What would fmin do?
Answer: There are no minima for this function, so it would just keep
iterating and making x smaller until it ran out of iterations.
●● Which line of code correctly implements M1 M2 pts, where M1 and
M2 are 3x3 matrices and pts is a 3xn matrix of x,y points?
Answer: pts_moved = M1 @ M2 @ pts.
●● What does the following matrix do?\
my_matrix = np.identity(3);
my_matrix[0,2] = x; my_matrix[1, 2] = y.
Answer: Translate by x, y.
PYTHON FOR ENGINEERS AND SCIENTISTS
COMPREHENSIVE TEST PAPER QUESTIONS
AND SOLUTIONS GRADED APLUS
●● Which of the following are approximations to derivatives?
Answer: All of the other responses are correct.
( f(x+h) - f(x) ) / h
( f(x) - f(x-h) ) / h
( f(x+h) - f(x-h) ) / h
●● When would you use Monte Carlo sampling methods to calculate an
integral?
Answer: When you can't use a numerical method that approximates the
area under the curve.
●● Suppose you called fmin with cos(x), x0 = 2pi + pi/4. What value
would fmin return for x, f(x)?
Answer: x=3pi, f(x)=-1.
, ●● If a function passed to fmin has more than one local minima, what
will fmin return?
Answer: One near the x0 given to fmin.
●● What does the parameter xtol control?
Answer: Stop when the differences between the parameters are smaller
than xtol.
●● Suppose your function was f(x) = 3x + 3, and you passed in x = 1.
What would fmin do?
Answer: There are no minima for this function, so it would just keep
iterating and making x smaller until it ran out of iterations.
●● Which line of code correctly implements M1 M2 pts, where M1 and
M2 are 3x3 matrices and pts is a 3xn matrix of x,y points?
Answer: pts_moved = M1 @ M2 @ pts.
●● What does the following matrix do?\
my_matrix = np.identity(3);
my_matrix[0,2] = x; my_matrix[1, 2] = y.
Answer: Translate by x, y.