Skip to content

Taylor series for sin

Python alternating series

Flowchart (ISO 5807)

StartInput x, nterm = xtotal = xi = 1, n − 1, 1term = −term·x·x / ((2i)·(2i + 1))total = total + termReturn totalEndFigure 1 — taylor_sin

Source code

Python
def taylor_sin(x, n):
    term = x
    total = x
    for i in range(1, n):
        term = -term * x * x / ((2 * i) * (2 * i + 1))
        total += term
    return total

The editor opens with this code — change it and the chart redraws.

Language
Python
Constructs
alternating series
Topic
Algorithms
Formats
Word, Visio, draw.io, PDF, SVG

Related examples