Function reference · Calculus

taylor

Computes a Taylor polynomial of an expression around a point.

Notation

taylor(expression, variable, center, degree)

Write it in an expression: nerdamer('taylor(sin(x),x,0,5)'), or in the Playground.

nerdamer.taylor

nerdamer.taylor(expression: ExpressionInput, variable: ExpressionInput, center: ExpressionInput, degree: ExpressionInput): Expression

A method on the default import. Arguments can be strings, as in Notation.

import { taylor }

import { taylor } from 'nerdamer/calculus';
taylor(expression: ExpressionInput, variable: ExpressionInput, center: ExpressionInput, degree: ExpressionInput): Expression

Import only this function, from nerdamer/calculus.

Parameters

expression
The expression to expand.
variable
The variable to expand in.
center
The point to expand around. It can't depend on variable.
degree
The highest power to keep, a nonnegative integer.

Returns

The polynomial, exact. If the derivatives can't be computed, the call is kept as it is.

Examples

Expand around 0 up to degree 5.

taylor(sin(x),x,0,5)
// → x+(-1/6)*x^3+(1/120)*x^5
Open in Playground

Coefficients stay exact fractions.

taylor(e^x,x,0,3)
// → 1+x+(1/2)*x^2+(1/6)*x^3
Open in Playground

Around another point, the terms are powers of x-1.

taylor(log(x),x,1,3)
// → (-1/2)*(-1+x)^2+(1/3)*(-1+x)^3-1+x
Open in Playground

The center can be symbolic, such as pi.

taylor(cos(x),x,pi,2)
// → -1+(1/2)*(x-pi)^2
Open in Playground

A polynomial stops once its derivatives are zero, so a high degree is fine.

taylor(x^3+x,x,0,100)
// → x+x^3
Open in Playground

log(x) has no Taylor polynomial around 0, so the call is kept as it is.

taylor(log(x),x,0,3)
// → taylor(log(x), x, 0, 3)
Open in Playground

Good to know

  • A negative or fractional degree is an error.
  • A symbolic or very large degree keeps the call as it is.
  • The variable is local to the call: a value stored under its name, as in x:5, isn't substituted inside it.

JavaScript examples

nerdamer.taylor('sin(x)', 'x', 0, 5).text()
// → x+(-1/6)*x^3+(1/120)*x^5

← Back to Function reference