sympy – find equations for the lines that are tagent and normal to the curve at (1, 2).

Chapter 2 Practice Exercises, p183

#  81. 
x = symbols('x')
y = Function('y')(x)
eq = x**2 + 2*y**2 - 9
f = sqrt((9 - x**2)/2)
dydx = diff(eq, x)
root = solve(dydx, diff(y, x, 1))

# dy/dx = -x/2*y
# the slope of tangent line at (1, 2)
m_t = Rational(-1, 2*2)
print m_t
y1 = m_t*(x - 1) + 2

# the slope of normal line at (1,2)
y2 = (-1/m_t)*(x - 1) + 2
eq, f, dydx, root, y1, y2

\begin{pmatrix}x^{2} + 2 y^{2}{\left (x \right )} - 9, & \sqrt{- \frac{x^{2}}{2} + \frac{9}{2}}, & 2 x + 4 y{\left (x \right )} \frac{d}{d x} y{\left (x \right )}, & \begin{bmatrix}- \frac{x}{2 y{\left (x \right )}}\end{bmatrix}, & - \frac{x}{4} + \frac{9}{4}, & 4 x - 2\end{pmatrix}

yl = 4
p = plot(f, -f, y1, y2, (x, -4, 4), ylim=(-yl, yl), title="x**2 + 2*y**2 = 9", show=False)
p[2].line_color = 'green'
p[3].line_color = 'purple'
p.show()

c2-pe-81

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