Taylor & Maclaurin
Taylor and Maclaurin Graphs
Plot a function and its Taylor polynomial. A center of 0 is the Maclaurin polynomial, and maclaurin(f, x, n) is the same expansion. The degree slider recalculates in the browser.
Generate Graph plots sin(x) together with taylor(sin(x),x,0,5) on one board. The function and the polynomial use different colors, and the expansion center is marked. The degree slider rebuilds each partial sum in the browser from the stored coefficients, from degree 0 through the requested degree, without another request.
The same graph card also plots the exponential, logarithm, cosine, reciprocal, and the cubic x^3+2*x^2+x+1. For log(x) at 1 and 1/x at 1, the sampled absolute difference is limited to the open interval where convergence was established. A polynomial stroke outside that interval is comparison only and is not a claim of accuracy. Zoom, pan, and export stay on this board. A center of 0 is titled as a Maclaurin polynomial.
Equation
taylor(sin(x),x,0,5)
Graph preview
How the Taylor polynomial is built
A Taylor polynomial of degree n at a center a is the unique polynomial of degree at most n that matches the function value and the first n derivatives at that center. Each coefficient is f^(k)(a)/k!. When the center is 0 the same polynomial is called a Maclaurin polynomial. DGS computes those derivatives with the existing differentiation routine and divides by factorial(k). It does not replace that calculation with a series shortcut, and a step is written only after the value has been computed.
The polynomial can exist on a larger set than the original function. log(x) is defined for x > 0, while its Taylor polynomial is defined for every real x. A finite radius, when one is established from singularities, guarantees convergence only on an open interval. Endpoint convergence is not claimed. If the center is outside the domain, or a derivative does not exist there, the result explains why the polynomial was not formed. A degree slider never asks for a higher order than the one that was computed.
Reading the input
taylor(sin(x),x,0,5)— This is a command. The name selects the routine, and the items inside the parentheses are its arguments.
Other versions of this example
These stay on this page so each version keeps the same explanation. Choose Try example to run a version in its Studio workflow, or copy it into the editable field below.
Sine at 0
Degree 5 at 0 is x-x^3/6+x^5/120. The curve and the polynomial stay on one board.
taylor(sin(x),x,0,5)
Exponential at 0
Degree 4 at 0 is 1+x+x^2/2+x^3/6+x^4/24.
taylor(exp(x),x,0,4)
Logarithm at 1
Degree 3 at 1 is (x-1)-(x-1)^2/2+(x-1)^3/3. Sampled error stays inside the open interval of convergence.
taylor(log(x),x,1,3)
Cosine at 0
Degree 6 at 0 is 1-x^2/2+x^4/24-x^6/720.
taylor(cos(x),x,0,6)
Reciprocal at 1
Degree 3 at 1 is 1-(x-1)+(x-1)^2-(x-1)^3. The original function is undefined at 0.
taylor(1/x,x,1,3)
Cubic polynomial
The degree-4 expansion at 0 is the original polynomial, so the remainder is 0.
taylor(x^3+2*x^2+x+1,x,0,4)
Try a change
- Lower the degree in the command, or move the degree slider after Generate Graph. The polynomial drops its highest term and the original curve stays in place.
- For taylor(log(x),x,1,3), keep the center inside x > 0. A center of 0 is rejected because the logarithm is undefined there.
Generate Graph plots the original function and the Taylor polynomial in different colors, marks the expansion center, and keeps zoom, pan, and export. The degree slider changes the partial sum locally. A sampled absolute difference is drawn only inside the region where it is supported. A stroke outside a known interval of convergence is comparison only.