- #1
BubblesAreUs
- 43
- 1
Homework Statement
Say, I was given a list, i.e. [1, 3, 7, 9, 12, 15, 24]
Now I'd like to find two values closest to an input ( say, x) so that I can produce an interval ( f(a), f(b)).
This interval would be used in an IVT problem where the intervals will be be part of [a,b] and will be used to compute the output of the initial input.
Homework Equations
given x
a < x < b
Find a and b within the list.
The Attempt at a Solution
I'm trying to tackle this problem via hand, but I'm also using python as well. I've thought of using a list, calculating the absolute difference between each element and then find the lowest difference.
List = [...]
x ( given number) = input("Enter given number")
Output = numpy.substract(List, x)
The lowest absolute difference should represent the closest value to the given number. I suppose I could take the second lowest difference as well, but I haven't really thought about a control loop for that problem.
On MATLAB, it's possible to take an array and given number, compute its absolute value and then use that to find its min, i.e. [,idx]= min(abs(List - x)). On Python, it doesn't seem like min() can be used for arrays/ lists.
Let's see how this goes...