I am using a simple function (y(x)), and I want to generate an x value from a certain y value. While typically reverse mapping does not give a single x value, I am using the maximum from my y values. This means that there will be a unique x value for the y value I input(the maximum). I don’t understand how to code this in c++
Share
If you don’t need interpolation, only exact reverse lookup, then it’s relatively straighforward:
Then your reverse lookup is just
lookup[y], which will return 0 (or a default-constructed value where applicable) ifyin fact was missing from the data.Be aware that my code is a bit inefficient, it looks up
yseveral times in the map, up to 3. You can optimize using iterators, but I’m concerned that obscures what’s going on if you’re not already familiar with them: