TheAlgorithms/Python · error · ValueError

Degree of the polynomial must be at least 1.

Error message

Degree of the polynomial must be at least 1.

What it means

Error "Degree of the polynomial must be at least 1." thrown in TheAlgorithms/Python.

Source

Thrown at maths/numerical_analysis/weierstrass_method.py:57

        >>> check(
        ...     lambda x: x**2 - 1,
        ...     2,
        ...     np.array([-1, 1]))
        True

        >>> check(
        ...     lambda x: x**3 - 4.5*x**2 + 5.75*x - 1.875,
        ...     3,
        ...     np.array([1.5, 0.5, 2.5])
        ... )
        True

    See Also:
        https://en.wikipedia.org/wiki/Durand%E2%80%93Kerner_method
    """

    if degree < 1:
        raise ValueError("Degree of the polynomial must be at least 1.")

    if roots is None:
        # Use perturbed complex roots of unity as initial guesses
        rng = np.random.default_rng()
        roots = np.array(
            [
                np.exp(2j * np.pi * i / degree) * (1 + 1e-3 * rng.random())
                for i in range(degree)
            ],
            dtype=np.complex128,
        )

    else:
        roots = np.asarray(roots, dtype=np.complex128)
        if roots.shape[0] != degree:
            raise ValueError(
                "Length of initial roots must match the degree of the polynomial."
            )

View on GitHub (pinned to f5988cc097)

Solutions

  1. Supply coefficients for a polynomial of degree at least 1.

When it happens

Trigger: Thrown at maths/numerical_analysis/weierstrass_method.py:57 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of TheAlgorithms/Python@f5988cc097 (2026-08-14). Data as JSON: /api/errors/ba4b3a5aecb4cf69. Report an issue: GitHub.