I don't have much mathematical background except for highschool and I'm struggling to design a very simple function.
I need a function f(x, y) that for the absolute difference of x and y would return a number between 0 and 4. If x, y are equal, it would return 4 lets say. If they have difference over some specific number (like 8) it would return value that is zero, or one that is very close to zero, and same goes for higher difference. It also is a requirement that the value that the function returns does not change linearly but lets say if the difference is 0, it would be 4, if its 2-3 it would already return ~2.
Then I need another function that does the same thing but instead of being based on the absolute difference of x and y, it is based on their percentage difference. Like, if x is ~35% different then y to return 0, if they are equal to return 4, again changing in non-linear way.
I'm probably terrible to describe - I need this for a system that compares vehicles from a database. So this is one component of it, lets say VehicleA has year of manufacturing 2000, and VehicleB is 2004, I want to assign a weight how similar they are:
My current out of my fingers solution:
(20 / (5 + ABS(2000 (this is `x`) - 2004 (this is `y`)) * 2))
The part with the percentage difference is if I compare vehicle engine size and power. I tried but did not succeed to create such function.
I "designed" it by playing with examples, I know there must be a more scientific way but I don't know where to look for :(
floorfunction? – zuggg Jul 16 '13 at 06:39