Concept of comparing numbers with tolerance

让人想犯罪 __ 提交于 2020-08-10 22:48:29

问题


I wanted to ask if there is a better way to compare numbers with a tolerance than mine.

Edit: It seems I was way to vague with my explanation. added some information into the text. This is concept only until now. I have not programmed any of it yet.

I want to compare around 6000 numbers with each other. The measured numbers [A] are slightly off than the numbers of [B]. [A] are the calculated molar masses of molecules (polymers to be specific). [B] are the measured molar masses of the molecules. Due to measurement errors and isotopes abundance the measured molar masses gradually increase with every added repeating unit of the polymer (= more elements in the molecule, = more offset). The difference in molar masses is relatively small in the lower molar masses (~ 0.1) and can range up to ~10 in the higher ranges. (Also, the numbers in [B] will never be the exact same as the calculated numbers in [A].) The range of the numbers goes from ~100.000000 up to ~76000.000000 (a lot to be precise). The practical numbers [A] and calculated numbers [B] are written in two different arrays (double) and not sorted.

My goal is to find the closest value of a number in [B] and link it to a number in [A] and mark them as “this molecule”. Every marked number/molecule will not be used again by any other number. One number of [B] only has one matching number in [A] which should be linked/written next to each other. In short, I have to find the number of [B] that fits my number in [A] the best. (I should also flag numbers when two or more values of [B] are to similar to [A] and not distinguishable. But that is another problem for another time) My idea for now is, taking one number of [A] and compare it with every number of [B]. The pair with the lowest difference/offset ( Num(A) – Num(B) ) is considered the same and further used.

Is there a better way to do this? Is there a function which does this on its own? Do you have suggestions how I could improve this method? Is it bad to use an array of length 6000?

Side information: I am programming in C Both practical and theoretical values are stored in an double arrays[6000] I am saving/writing the data in excel like table structures

来源:https://stackoverflow.com/questions/63252539/concept-of-comparing-numbers-with-tolerance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!