Table of contents
CSPICE_RQUAD finds the roots of a quadratic equation.
Given:
a,
b,
c the coefficients of a quadratic polynomial
2
a * x + b * x + c.
help, a
DOUBLE = Scalar
help, b
DOUBLE = Scalar
help, c
DOUBLE = Scalar
the call:
cspice_rquad, a, b, c, root1, root2
returns:
root1,
root2 the roots of the equation
2
a * x + b * x + c = 0.
help, root1
DOUBLE = Array[2]
help, root2
DOUBLE = Array[2]
`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.
None.
Any numerical results shown for this example may differ between
platforms as the results depend on the SPICE kernels used as input
and the machine specific arithmetic implementation.
1) Calculate the roots of the following quadratic equation:
2
x + 2x + 3 = 0
Example code begins here.
PRO rquad_ex1
cspice_rquad, 1.d, 2.d, 3.d, root1, root2
print, 'Solutions using SPICE:'
print, FORMAT='(" Root #1:", 2F12.7)', root1
print, FORMAT='(" Root #2:", 2F12.7)', root2
;;
;; Check the IDL function.
;;
roots = fz_roots([3,2,1])
print, 'Solutions using IDL native code:'
print, FORMAT='(" Root #1:", 2F12.7)', roots(0)
print, FORMAT='(" Root #2:", 2F12.7)', roots(1)
END
When this program was executed on a Mac/Intel/IDL8.x/64-bit
platform, the output was:
Solutions using SPICE:
Root #1: -1.0000000 1.4142136
Root #2: -1.0000000 -1.4142136
Solutions using IDL native code:
Root #1: -1.0000000 -1.4142134
Root #2: -1.0000000 1.4142134
None.
1) If the input coefficients `a' and `b' are both zero, the error
SPICE(DEGENERATECASE) is signaled by a routine in the call
tree of this routine. The output arguments are not modified.
2) If any of the input arguments, `a', `b' or `c', is undefined,
an error is signaled by the IDL error handling system.
3) If any of the input arguments, `a', `b' or `c', is not of the
expected type, or it does not have the expected dimensions and
size, an error is signaled by the Icy interface.
4) If any of the output arguments, `root1' or `root2', is not a
named variable, an error is signaled by the Icy interface.
None.
1) No checks for overflow of the roots are performed.
ICY.REQ
None.
J. Diaz del Rio (ODC Space)
E.D. Wright (JPL)
-Icy Version 1.0.1, 17-JUN-2021 (JDR)
Edited the header to comply with NAIF standard. Added example's
problem statement and reformatted example's output.
Added -Parameters, -Exceptions, -Files, -Restrictions,
-Literature_References and -Author_and_Institution sections.
Removed reference to the routine's corresponding CSPICE header from
-Abstract section.
Added arguments' type and size information in the -I/O section.
-Icy Version 1.0.0, 16-JUN-2003 (EDW)
roots of a quadratic equation
|