> From davidw@ruby.ed.ac.uk Tue Jul 12 09:39:39 PDT 1994 > Subject: Re: roots of 2nd order polynomial (SHAME!) Bruno Nicoletti writes: # I must really be getting old, my memory is going along with my eyesight # and hair. I want to find the min/max of a cubic curve and to do this I # need to find the roots of a 2nd order polynomial. # # f(x) = ax^2 + bx + c # # however I can't remember it, I don't have it in any of my reference books # and forget how to derive it. The roots look something like, # # root 1 = (X + sqrt(b^2 - 4ac)) / 2a # root 2 = (X - sqrt(b^2 - 4ac)) / 2a # # What is the X? I think it may be "-b" but I'm not sure. It is "-b". Numerical Recipes in C recommend that you don't use this form, however, because if either a or c are small, then root 1 involves taking the difference of two nearly equal quantities, leading to inaccuracies. They recommend that you find: V = (b + sgn(b)*sqrt(b^2 - 4ac)) / 2 and then: root 1 = V/a root 2 = c/V Article 6021 of comp.graphics.algorithms: Newsgroups: comp.graphics.algorithms Path: kpc!news.kpc.com!sgiblab!cs.uoregon.edu!usenet.ee.pdx.edu!fastrac.llnl.gov!lll-winken.llnl.gov!sol.ctr.columbia.edu!howland.reston.ans.net!EU.net!sunic!news.uni-c.dk!diku!torbenm From: torbenm@diku.dk (Torben AEgidius Mogensen) Subject: Re: roots of 2nd order polynomial (SHAME!) Message-ID: <1994Jul7.140534.12246@odin.diku.dk> Sender: torbenm@embla.diku.dk Date: Thu, 7 Jul 1994 14:05:34 GMT References: Organization: Department of Computer Science, U of Copenhagen Lines: 61 davidw@ruby.ed.ac.uk (David Wren) writes: >In article , Bruno Nicoletti >writes: ># ># root 1 = (X + sqrt(b^2 - 4ac)) / 2a ># root 2 = (X - sqrt(b^2 - 4ac)) / 2a ># ># What is the X? I think it may be "-b" but I'm not sure. ># >It is "-b". >Numerical Recipes in C recommend that you don't use this form, however, >because if either a or c are small, then root 1 involves taking the >difference of two nearly equal quantities, leading to inaccuracies. >They recommend that you find: >V = (b + sgn(b)*sqrt(b^2 - 4ac)) / 2 >and then: >root 1 = V/a >root 2 = c/V This can't be right. If b>0 then V = b+sqrt(b^2-4ac)/2. This makes root 1 = (b+sqrt(b^2-4ac))/2a. which is the negation of the root (-b-sqrt(b^2-4ac))/2a. If b<0, we get root 1 =(b-(sqrt(b^2-4ac))/2a which is the negation of the root (-b+sqrt(b^2-4ac))/2a. So I believe it must be root 1 = -V/a Looking at c/V, when b>0 we get root 2 = c/(b+sqrt(b^2-4ac)/2) = 2c/(b+sqrt(b^2-4ac) = 2c(b-sqrt(b^2-4ac))/(b+sqrt(b^2-4ac))(b-sqrt(b^2-4ac)) = 2c(b-sqrt(b^2-4ac))/4ac = (b-sqrt(b^2-4ac))/2a which is the negation of the root (-b+sqrt(b^2-4ac))/2a. Similarly we get the wrong sign when b<0, so it must be root 2 = -c/V Alternatively, we can retain V/a and c/V as the roots by redefining V: V = (-b-sgn(b)*sqrt(b^2-4ac))/2 Torben Mogensen (torbenm@diku.dk)