Since you apparently want something Mathematica-like, as opposed to a procedural loop, here's a take on it. Note, as belisariusbelisarius commented, we really ought to check whether the exact root has accidentally been found. That adds some case-checking. I'll discuss pattern-checking the arguments later. You may note I defined a realQ
to replace NumericQ
. This may be over-fastidious, but complex numbers will not work.
Using a PatternTest versus a Condition for pattern matchingUsing a PatternTest versus a Condition for pattern matching
_?NumericQ equivalent for lists_?NumericQ equivalent for lists
How to program a F::argx message?How to program a F::argx message?
*More elegant wayMore elegant way
*Quick way to use conditioned patterns when defining multi-argument function?Quick way to use conditioned patterns when defining multi-argument function?
*How to avoid repeated pattern tests in function definitionsHow to avoid repeated pattern tests in function definitions
For users of V9 and earlier, you can use these replacements for DeleteDuplicatesBy
and BooleanQ
. The code for DeleteDuplicatesBy
below is basically Mr.Wizard's myDeDupeBy
in his answer to his question, DeleteDuplicatesBy is not performing as I'd hoped. Am I missing something?DeleteDuplicatesBy is not performing as I'd hoped. Am I missing something? Perhaps everyone should be using it.