{"record":{"id":"ba4b3a5aecb4cf69","repo":"TheAlgorithms/Python","slug":"degree-of-the-polynomial-must-be-at-least-1","errorCode":null,"errorMessage":"Degree of the polynomial must be at least 1.","messagePattern":"Degree of the polynomial must be at least 1\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"maths/numerical_analysis/weierstrass_method.py","lineNumber":57,"sourceCode":"        >>> check(\n        ...     lambda x: x**2 - 1,\n        ...     2,\n        ...     np.array([-1, 1]))\n        True\n\n        >>> check(\n        ...     lambda x: x**3 - 4.5*x**2 + 5.75*x - 1.875,\n        ...     3,\n        ...     np.array([1.5, 0.5, 2.5])\n        ... )\n        True\n\n    See Also:\n        https://en.wikipedia.org/wiki/Durand%E2%80%93Kerner_method\n    \"\"\"\n\n    if degree < 1:\n        raise ValueError(\"Degree of the polynomial must be at least 1.\")\n\n    if roots is None:\n        # Use perturbed complex roots of unity as initial guesses\n        rng = np.random.default_rng()\n        roots = np.array(\n            [\n                np.exp(2j * np.pi * i / degree) * (1 + 1e-3 * rng.random())\n                for i in range(degree)\n            ],\n            dtype=np.complex128,\n        )\n\n    else:\n        roots = np.asarray(roots, dtype=np.complex128)\n        if roots.shape[0] != degree:\n            raise ValueError(\n                \"Length of initial roots must match the degree of the polynomial.\"\n            )","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/maths/numerical_analysis/weierstrass_method.py#L39-L75","documentation":"Error \"Degree of the polynomial must be at least 1.\" thrown in TheAlgorithms/Python.","triggerScenarios":"Thrown at maths/numerical_analysis/weierstrass_method.py:57 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Supply coefficients for a polynomial of degree at least 1."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}