Talk:Roots of a quadratic function
obscure algorithm ?
I don't like being pushed to use obscure (but more stable) algorithm over algorithm everyone instantly recognises. Said that, I could live with it. But I want to point that:
- - link for "What Every Scientist Should Know About Floating-Point Arithmetic" is dead;
- - one can google for it, but formatting is different, so how to find what "page 9" actually is?
- - quoted in the text, "Suggested by Middlebrook (D-OA), a better numerical method: to define two parameters q=sqr(ac)/b (...)" naturally fails over if a>0 and c<0.
"do it better" ?
I clearly see
come some of programs (Ada, and some marked as "translation of Ada") use
there correct way is
I wonder why noone spotted this earlier!
Forsythe, Michael Malcolm and Cleve Moler suggest to try it on a=1, b=-105, c=1, but Ada sample code uses -10e5, which is indeed -1e6 (-106), if I was not wrong since I knew the "e" notation... --ShinTakezou 21:24, 22 June 2009 (UTC)
Basically all the test cases had a = 1, :-) So I added some test cases especially where a ≠ 1, hence 2*a ≠ 2/a.... NevilleDNZ 14:28, 16 September 2010 (UTC)
- In the example above (2nd line) (-106) isn't the same as -1e6. The former is -1,000,000 and the latter is +1,000,000. --Gerard Schildberger 18:11, 25 June 2011 (UTC)
- It all depends if the infix (negative) operator has more or less priority then the exponent operator. -- Gerard Schildberger (talk) 09:14, 13 November 2020 (UTC)
Dumontier, hope you don't mind me replacing your example code. I understood that you were trying to illustrate the generality of
p. however your example used a quadratic, that had already been shown above. If you were trying to illustrate some other point I apologise! --Tikkanz 23:14, 14 October 2009 (UTC)
I just provided a (more) correct C version, and am now tempted to remove other C examples, because the task specifically mentioned the shortcoming of the naive method, yet they went on that route anyway. Opinions? --Ledrug 09:08, 25 June 2011 (UTC)
Wait, what? The existing C and C++ code gives 10^20 and 10^-20 as roots to equation
x^2 - 10^-20 x + 1 == 0? What the? --Ledrug 09:22, 25 June 2011 (UTC)
Eh never mind that, and sorry about making a mess on the incorrect tags--I need sleep... --Ledrug 09:40, 25 June 2011 (UTC)
Why are there 4 functions for clojure?
What I mean is that all of that can be simplified into: <lang clojure>(defn quadratic
"Compute the roots of a quadratic in the form ax^2 + bx + c = 0 Returns any of nil, a float, or a vector." [a b c] (let [sq-d (Math/sqrt (- (* b b) (* 4 a c))) f #(/ (% b sq-d) (* 2 a))] (cond (neg? sq-d) nil (zero? sq-d) (f +) (pos? sq-d) [(f +) (f -)] :else nil))) ; maybe our number ended up as NaN</lang>
I find it ridiculous to have that much verbiage on 1 example.