Differentiating Trigonometric Functions

Differentiating Trigonometric Functions#

Below, we have the rules for differentiating trigonometric functions:

\[ \textrm{If }y = \sin{(x)}\textrm{ then }\frac{dy}{dx} = \cos{(x)} \]
\[ \textrm{If }y = \cos{(x)}\textrm{ then }\frac{dy}{dx} = -\sin{(x)} \]

When we have constants multiplying the trigonometric functions and coefficients multiplying our \(x\), we can use the following rules:

\[ \textrm{If }y = a\sin{(bx)}\textrm{ then }\frac{dy}{dx} = a \times b \times \cos{(x)} \]
\[ \textrm{If }y = a\cos{(bx)}\textrm{ then }\frac{dy}{dx} = -a \times b \times \sin{(x)} \]

Example

Differentiate:

  1. \(y = \sin(9x)\)

  2. \(y = 4 \cos\left(\frac{x}{2}\right)\)

  3. \(y = -2\cos(7x)\)

Solution:

  1. Using the rule:

\[ \textrm{If }y = a\sin{(bx)}\textrm{ then }\frac{dy}{dx} = a \times b \times \cos{(x)} \]

Now that we have \(y=\sin(9x)\), so \(a=1\) and \(b=9\). So \(\frac{dy}{dx} = 9\cos(9x)\).

  1. Using the rule:

\[ \textrm{If }y = a\cos{(bx)}\textrm{ then }\frac{dy}{dx} = -a \times b \times \sin{(x)} \]

Not that we have \(y=4\cos\left(\frac{x}{2}\right)\), so \(a=4\) and \(b=\frac{1}{2}\)

\[ \frac{dy}{dx} = -4 \times \frac{1}{2} \times \sin\left(\frac{x}{2}\right) = -2\sin\left(\frac{x}{2}\right). \]
  1. Using the rule:

\[ \textrm{If }y = a\cos{(bx)}\textrm{ then }\frac{dy}{dx} = -a \times b \times \sin{(x)} \]

Note that we have \(y=-2\cos(7x)\), so \(a=-2\) and \(b=7\)

\[ \frac{dy}{dx} = -(-2) \times (7\sin(7x)) = 14\sin(7x). \]

The sympy symbolic differentiation can be used for trigonometric functions. However, we must use the sympy versions of sin and cos.

from sympy import symbols, diff, sin, cos

x = symbols('x')

diff(sin(9 * x))
\[\displaystyle 9 \cos{\left(9 x \right)}\]
diff(4 * cos(x / 2))
\[\displaystyle - 2 \sin{\left(\frac{x}{2} \right)}\]
diff(-2 * cos(7 * x))
\[\displaystyle 14 \sin{\left(7 x \right)}\]

Bragg Equation

In X-ray crystallography, the Bragg equation relates the distance \(d\) between successive layers in a crystal, the wavelength of the X-rays, \(\lambda\), an integer \(n\), and the angle through which the X-rays are scattered, \(\theta\), in the equation:

\[ \lambda = \frac{2d}{n}\sin{\theta} \]

What is the rate of change of \(\lambda\) with \(\theta\)?

Solution: The question is asking us to find \(\frac{d\lambda}{d\theta}\). So as \(n\) and \(d\) are constants, we can use the rule:

\[ \textrm{If }y = a\sin{(bx)}\textrm{ then }\frac{dy}{dx} = a \times b \times \cos{(x)} \]

So we have \(a=\left(\frac{2d}{n}\right)\) and \(b=1\), with \(\lambda\) as \(y\) and \(\theta\) as \(x\), therefore:

\[ \frac{d\lambda}{d\theta} = \left(\frac{2d}{n}\right) \times 1 \times \cos\theta = \frac{2d}{n}\cos\theta. \]

n, d, theta = symbols(r'n d \theta')

diff(2 * d / n * sin(theta), theta)
\[\displaystyle \frac{2 d \cos{\left(\theta \right)}}{n}\]