Question: Write a function simple_minimizer which takes in four arguments: A function reference func which represents a 1-D function, e.g. f(x) = x^2. You can assume
Write a function simple_minimizer which takes in four arguments:
A function reference func which represents a 1-D function, e.g. f(x) = x^2. You can assume that it also will work on a Numpy array, so that if you do func(x_values), you will get a corresponding array of y values.
A start and end, floats which represent the region to search for a minimum. (Throw a ValueError if start > end.)
An optional param num which defaults to 100.
It should then evaluate func at num evenly-spaced points between start and end (endpoint inclusive) and return two values: The x corresponding to the minimum value of f(x), followed by the actual minimum value. For example, if out of all the values you tested the minimum was f(0.5) = 2.4, you would return (0.5, 2.4). Example: my_func = lambda x: x**2 simple_minimizer(my_func, -1.75, 2.25, num=5) # Should return (0.25, 0.0625)
For this assignment, you should not use loops! You should be using vectorized operations. Functional iterators are also not allowed. The following operations will be deducted: for, while, comprehensions (like [x for x in range(10)], map(), and filter().
Use python 3.8
Thank you!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
