sympy – plot(): draw many graphs on one window.

Graph y = \frac{1}{2 \sqrt{x}} in a window that has 0 <= x <= 2. Then, on the same screen, graph
y = \frac{1}{h} \left(\sqrt{h + x} - \sqrt{x} \right)
for h = -1, -0.5, -0.1, 0.1, 0.5, 1.

from sympy import *

init_printing()
x, h = symbols('x h')
y1 = 1/(2*sqrt(x))
y2_0 = (sqrt(x + h) - sqrt(x))/h
y2 = Lambda((x, h), y2_0)
h = (-1, -0.5, -0.1, 0.1, 0.5, 1)

ff = []
for n in h:
    f = y2(x, n)
    ff.append(f)
pprint(ff)
plot(y1, ff[0], ff[1], ff[2], ff[3], ff[4], ff[5], (x, -1, 2), ylim=(0, 10))

\begin{bmatrix}\sqrt{x} - \sqrt{x - 1}, 2.0 \sqrt{x} - 2.0 \sqrt{x - 0.5},
10.0 \sqrt{x} - 10.0 \sqrt{x - 0.1}, - 10.0 \sqrt{x} + 10.0 \sqrt{x + 0.1},
- 2.0 \sqrt{x} + 2.0 \sqrt{x + 0.5}, - \sqrt{x} + \sqrt{x + 1}\end{bmatrix}

e2.1-59

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 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