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))
e2.5-81a

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))
e2.5-81b

step function
e2.5-81c

Composite graph of above all functions
e2.5-81d

About janpenguin

Email: janpenguin [at] riseup [dot] net 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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s