




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





โโ 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. โโ