Skip to content

solveCubic

Core and matricesfunctionOpenCV 5.0.0
import { solveCubic } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

ARGUMENTScoeffs, roots
FUNCTIONsolveCubic
RETURN TYPEnumber
Call structure. A void return can still write to destination arguments. The parameter descriptions define inputs, outputs and ownership.

Finds the real roots of a cubic equation.

The function solveCubic finds the real roots of a cubic equation:

  • if coeffs is a 4-element vector:
\texttt{coeffs} [0] x^3 +  \texttt{coeffs} [1] x^2 +  \texttt{coeffs} [2] x +  \texttt{coeffs} [3] = 0
  • if coeffs is a 3-element vector:
x^3 +  \texttt{coeffs} [0] x^2 +  \texttt{coeffs} [1] x +  \texttt{coeffs} [2] = 0

The roots are stored in the roots array.

solveCubic(coeffs: Mat, roots: Mat): number;
coeffs

equation coefficients, an array of 3 or 4 elements.

roots

Output destination, filled by the native operation. output array of real roots that has 0, 1, 2 or 3 elements.

Returns

number of real roots. It can be -1 (all real numbers), 0, 1, 2 or 3.

These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.