Documentation moved.
This entry is documented with its primary interface. Open the documentation →
Function
src/index.ts:1041nerdamer.completeSquare
nerdamer.completeSquare(expr: ExpressionInput, variable?: string): CompleteSquareResultCompletes the square for a quadratic expression.
For a*x^2+b*x+c, the returned expression has the form
a*(x+h)^2+k, with h=b/(2*a) and k=c-b^2/(4*a).
Parameters
| Name | Type | Description |
|---|---|---|
expr | ExpressionInput | Quadratic expression to rewrite. |
variable | string | Variable to use. Defaults to the first variable in the expression. |
Returns
CompleteSquareResult — The quadratic coefficient, shift, remainder, selected variable, and rewritten expression.
Examples
const result = completeSquare('x^2+6*x+1');
result.expression.text({ sort: true }); // "(3+x)^2-8"