rquad_c |

Table of contents## Procedurerquad_c ( Roots of a quadratic equation ) void rquad_c ( SpiceDouble a, SpiceDouble b, SpiceDouble c, SpiceDouble root1[2], SpiceDouble root2[2] ) ## AbstractFind the roots of a quadratic equation. ## Required_ReadingNone. ## KeywordsMATH POLYNOMIAL ROOT ## Brief_I/OVARIABLE I/O DESCRIPTION -------- --- -------------------------------------------------- a I Coefficient of quadratic term. b I Coefficient of linear term. c I Constant. root1 O Root built from positive discriminant term. root2 O Root built from negative discriminant term. ## Detailed_Inputa, b, c are the coefficients of a quadratic polynomial 2 ax + bx + c. ## Detailed_Outputroot1, root2 are the roots of the equation, 2 ax + bx + c = 0. root1 and root2 are both arrays of length 2. The first element of each array is the real part of a root; the second element contains the complex part of the same root. When a is non-zero, root1 represents the root _____________ / 2 - b + \/ b - 4ac --------------------------- 2a and root2 represents the root _____________ / 2 - b - \/ b - 4ac --------------------------- . 2a When a is zero and b is non-zero, root1 and root2 both represent the root - c / b. ## ParametersNone. ## Exceptions1) If the input coefficients `a' and `b' are both zero, the error SPICE(DEGENERATECASE) is signaled. The output arguments are not modified. ## FilesNone. ## ParticularsNone. ## ExamplesThe numerical results shown for these examples may differ across platforms. The results depend on the SPICE kernels used as input, the compiler and supporting libraries, and the machine specific arithmetic implementation. 1) Humor us and suppose we want to compute the "golden ratio." The quantity `r' is defined by the equation 1/r = r/(1-r), which is equivalent to 2 r + r - 1 = 0. The following code example does the job. Example code begins here. /. Program rquad_ex1 ./ #include <stdio.h> #include "SpiceUsr.h" int main( ) { /. Local variables. ./ SpiceDouble root1 [ 2 ]; SpiceDouble root2 [ 2 ]; /. Compute "golden ratio." The root we want, ___ / -1 + \/ 5 -----------, 2 is contained in root1. ./ ## Restrictions1) No checks for overflow of the roots are performed. ## Literature_ReferencesNone. ## Author_and_InstitutionN.J. Bachman (JPL) J. Diaz del Rio (ODC Space) ## Version-CSPICE Version 1.0.1, 04-AUG-2021 (JDR) Edited the header to comply with NAIF standard. Created complete code examples from existing code fragments. -CSPICE Version 1.0.0, 13-JUN-1999 (NJB) ## Index_Entriesroots of a quadratic equation |

Fri Dec 31 18:41:11 2021