Docsity

APPLIED NUMERICAL METHODS WITH PYTHON FOR ENGINEERS AND SCIENTISTS COMPREHENSIVE TEST PAPE, Exams of Mathematical Modeling and Simulation

Toggle sidebar
bg1
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.
pf3
pf4
pf5
pf8

Partial preview of the text

Download APPLIED NUMERICAL METHODS WITH PYTHON FOR ENGINEERS AND SCIENTISTS COMPREHENSIVE TEST PAPE and more Exams Mathematical Modeling and Simulation in PDF only on Docsity!

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.

car_1 and car_2 have the .... Answer: same property names and different property values. โ—โ— What is wrong in the following class definition? class Foo: def init(self, p1): save_p1 = p1; def use_p1(self): return save_p1. Answer: Missing the self. in front of save_p1. โ—โ— When does actually get executed in class QuarterCar? Answer: When you create the quarter car class instance. โ—โ— What's wrong with the above code? xi+1 = x+3+ yi * 2 Yi+1 = 2x+i+3yi. Answer: Uses x at the next time step to calculate y. โ—โ— What should [line] be in the equation dx/dt = 3x+2; x = x_start delta_t = 0.

for _ in range(0,1000): [line] print (f"x after 1000 time steps is {x}")? Answer: x=x + (3 x + 2) * delta_t โ—โ— What should [stuff] be in the equation dx/dt = axt+b; a = 3, b = 2; def my_deriv(x, t, a, b): return a x t + b; ts = np.arange(0.0, t_final, t_step); values = integrate.odeint([stuff]) Answer: my_deriv, 0, ts, args=(3,2). โ—โ— Given a tuple t = (1, 2, 3), which are valid tuple statements? Select all that are. Answer: t = "Tuple" a, _, c = t foo = t[0:1]

Answer: a='b', b='a', c='c'. โ—โ— What makes for a 'good' plot/visualization? Answer: All of the above. Different colors are distinguishable even if someone is color blind/it is printed in gray scale The plot visually displays the "point" The plot lines/markers can be clearly distinguished Axes are clearly labeled with units The layout makes maximum use of the available space โ—โ— After the function call of def func(a, b): c=b-a; return c; val = func(3,2), what are the values of the variables a, b, and c? Answer: Those variables do not exist, they only exist in the function. โ—โ— What is the value of val in the function def func(a, b): c = a + b; return c; a = 5; b=3; val = func(2, 4)? Answer: 6.

โ—โ— What is the value of val in the function def func(a, b): c=b-a; return c; a = 5; b=3; val = func(b, a)? Answer: - 2. โ—โ— What data structure makes the most sense to keep information about a data set you've captured? Answer: dictionary. โ—โ— Which of the following actually copy data on assignment? Answer: strings, integers, floats. โ—โ— Which of these are 'bad' coding practices? Answer: Changing lists 'in-place', Re-using x-over and over again. โ—โ—