04-30-2005, 07:43 AM | #1 (permalink) |
Psycho
Location: Cow Country, CT
|
Optimization search code
I am working on am senior design project and i am having a large problem with my search. My microcontroller takes and input then compares it to a past value and then makes a dession about what to do bease on the past input. seems simple enough... no way... due to round off errors the program is always getting false input. My ? is can someone help me to write a search program that could attempt to find a unkown value in a almost unordered string... something like finding 2 when the numbers are 1 1 3 2 4 3 5 5 4 6 7 8 8 7 9
something like that... i mean not exactly like that... but that is kind of what i am dealing with. if you need anymore info let me know.... thanks in advance
__________________
No, they arnt breasts, they are personalities, because its ok to like a girl for her personalities. |
05-01-2005, 08:07 AM | #2 (permalink) |
Junkie
|
I'm confused by your question. You are trying to find a number in an unordered list right? Just do a simple linear search to find it. It sounds like you are working with floating point numbers though which means rounding errors will ruin your equality. So then use an epislon factor to determine equality.
For instance here is some psuedo code Code:
int Search(List L, double number) { e=10^-6 for i=1 to L.length if (abs(L[i]-number)<e) return i return -1 } Last edited by Rekna; 05-01-2005 at 08:09 AM.. |
Tags |
code, optimization, search |
|
|