Edit1: Changed question to fit the guidlines. I already asked this question but it got taken down for being to vague. Rewrote the question to make it clearer.
My goal is to compare around 6000 numbers with each other and find the matching/closest pair. But no number is equal to the other and has an error/tolerance.
My starting condition is two data blocks saved in two arrays are. Data block [A] are numbers of theoretical calculated numbers. Data block [B] are real measured numbers. [B] are the real measurements of an Object and should be as close as possible to [A] (measurement error). I have to find Am to the matching Bn .
Every number of [A] is higher than the previous one by a value of X or Y. Both X and Y are possible and therefor a “tree” like structure is displayed afterwards (not important for the comparison process). Every number in [B] has a measurement error and every “addition” of X and Y has a 1.1% chance of being 1 % off. This means in higher ranges of numbers the offset from the theoretical numbers [A] will get larger. The closest fit of B_n with a number of [A] (A_m) should be linked/highlighted/somehow memorized.
My idea is to calculate the difference/offset between one number of [B] (B_n) and every number of [A]. The pair with the lowest offset should be memorizing and the offset should be saved as well.
This would look like this (still not a code just a concept):
z=1
loop {
offset1 = B_n – A_m
offset2 = B_n – A_m+z
is offset1 lower than offset2?
Yes: z=z+1;
No: offset1 = offset2;
memorize m
}
Is there function which does this on it`s own/does it do similar/does it with differently with the same result? Comparing numbers and return the closest pair. IS this methode valid to use?
Side information: Programming language = C // Number Data Blocks = two arrays of length 3000 and more // Number Range: ~100.000001 up to ~100,001.000001 //