## sympy – sawtooth function

Calculus and Analytic Geometry, George B. Thomas and Ross L. Finney
Exercises 2.5 81, p163

```from sympy import *

def pprints(func, *funcs):
breaker = '='*30
pprint(func)
print breaker
if funcs is None:
return

for f in funcs:
pprint(f)
print breaker

init_printing()

t = symbols('t')
s = 0.78540 - 0.63662*cos(2*t) - 0.07074*cos(6*t) - 0.02546*cos(10*t) - \
0.01299*cos(14*t)
dsdt = diff(s, t)

# step function
g1 = (1, (t, -pi, -pi/2.0)) # y = 1
g2 = (-1, (t, -pi/2.0, 0))  # y = -1
g3 = (1, (t, 0, pi/2.0))   # y = 1
g4 = (-1, (t, pi/2.0, pi))  # y = -1

pprints(s, dsdt)

plot(s, (t, -pi, pi))
plot(dsdt, (t, -pi, pi))
plot(g1, g2, g3, g4, ylim=(-1.5, 1.5))
plot(g1, g2, g3, g4, (s, (t, -pi, pi)), (dsdt, (t, -pi, pi)))
```

s = 0.78540 – 0.63662*cos(2*t) – 0.07074*cos(6*t) – 0.02546*cos(10*t) – \
0.01299*cos(14*t)
plot(s, (t, -pi, pi))

dsdt = 1.27324*sin(2*t) + 0.42444*sin(6*t) + 0.2546*sin(10*t) + 0.18186*sin(14*t)
plot(dsdt, (t, -pi, pi))

step function

Composite graph of above all functions

## About janpenguin

Email: k2.mountain [at] gmail [dot] com Every content on the blog is made by Free and Open Source Software in GNU/Linux.
This entry was posted in Python, Science and technologies and tagged , , , , , , , , . Bookmark the permalink.