>Business >Derivative of the Sine and Cosine

### Derivative of the Sine and Cosine

Several machine learning algorithms consist of an optimization procedure for differing purposes. Optimization is in reference to the issue of minimizing an objective function through alteration of the value of its inputs.

Optimization algorithms are reliant on the leveraging of derivatives in order to comprehend how to modify (increase or decrease) the input values to the objective function, in order to reduce or maximize it. It is, hence, critical that the objective function being considered is differentiable.

The two fundamental trigonometric functions, the sine and the cosine, provide a good opportunity to comprehend the manoeuvres that may be needed in identifying the derivatives of differentiable functions. These two functions become particularly critical if we perceive of them as the basic building blocks of more complicated functions.

In this guide by AICoreSpot, you will find out how to identify the derivative of the sine and cosine functions.

Upon going through this guide, you will  be aware of:

• How to identify the derivative of the sine and cosine functions through application of various rules ranging from algebra, trigonometry, and limits.
• How to identify the derivative of the sine and cosine functions in Python.

Tutorial Overview

This guide is subdivided into three portions, which are:

• The Derivative of the Sine Function
• The Derivative of the Cosine Function
• Identifying derivatives in Python

The Derivative of the Sine Function

The derivative f’(x) of some function, f, at a specific point, may be mentioned as:

We will begin by looking into the sine function. Therefore, let’s first replace for f(x) = sin x:

If we observe the trigonometric identities, we discover that we might apply the addition formula to expand the sin(x+h) term:

If we observe the trigonometric identities, we discover that we might apply the addition formula to expand the sin (x+h+ term.

sin(x + y) = sin x cos y + cos x sin y

Indeed, by replacing y with h we can go about defining the derivative of sin x as:

We may simplify the expression even more through application of one of the limit laws, which specifies that the limit of a sum of functions is equivalent to the sum of their limits.

We can simplify even more by bringing out any common factor which happens to be a function of x. In this fashion, we can factorize the expression to obtain the total of two separate limits that are not dependent on x:

Identifying solutions to every one of these two limits will provide us the derivative of sin x.

Let’s begin by taking a gander at the first limit.

Remember that we may indicate angle, h in radians, on the unit circle. The sine of h would then be provided by the perpendicular to the x-axis (BC), at the point that meets the unit circle.

We will be contrasting the region of differing sectors and triangles, with sides subtending the angle h, in an effort to make inferences about how ((sin h / h) behaves as the value of h gets close to zero. For this reason, consider first the region of sector OAB.

The region of a sector can be defined in terms of the circle radius, r, and the length of the arc AB, h. As the circle being considered is the unit circle, then r=1.

Area_of_sector_OAB = r h / 2 = h / 2

We can contrast the region of the sector OAB that we have just discovered, to the region of the triangle OAB within the same sector.

The area of this triangle is defined with regards to its height, BC = sin h, and the length of its foundation, OA = 1.

area_of_triangle_OAB = (BC) (OA) / 2 = (sin h) / 2

As we can obviously see that the region of the triangle, OAB that we have just considered is smaller than the area of the sector that is consisted within, then we might state that:

(sin h) / 2 < h / 2

(sin h) / h < 1

This is the first article of data that we have collected with regards to the behaviour of ((sin h) / h), which informs us that is upper limit value will not surpass 1.

Let us now move forward to take up a second triangle, OAB’ that is personified by a bigger area than that of sector, OAB. We can leverage this triangle to furnish us with the second piece of info with regards to the behaviour of ((sin h) / h, which is its lower limit value.

Through application of the attributes of similar triangles to relate OAB’ to OCB, provides us data with regards to the length, B’A that we require to compute the area of the triangle:

B’A / OA = BC / OC = (sin h) / (cos h)

Therefore, the region of the triangle OAB’ might be computed as:

Area_of_triangle_OAB’ = (B’A) (OA) / 2 = (sin h) / (2 cos h)

Contrasting the area of triangle OAB’ to that of sector OAB, we can observe that the former is now bigger.

H / 2 < (sin h) / (2 cos h)

Cos h <{sin h) / h

This is the second article of data that we required, which informs us that the lower limit value of ((sin h / h) does not drop below cos h. We are also aware that as h gets close to 0, the value of cos h gets close to 1.

Therefore, putting the two pieces of data together, we discover that as h gets smaller and smaller, the value of ((sin h) / h) itself is squeezed to 1 by its upper and lower limits. This is indeed, called the squeeze or sandwich theorem.

Let’s now move forward to manage the second limit.

Through application of standard algebraic rules:

We can go about manipulating the second limit in the following manner:

We can then go about expressing this limit with regards to sine, through application of the Pythagorean identity from trigonometry, sin squared h = 1 – cos squared h

Following the application of another limit law, which specifies that the limit of a product is equal to the product of the separate limits:

We have already handled the first limit of this product, and we have discovered that this possesses a value of 1.

The second limit of this product is signified by a cos h in the denominator, which gets to a value of 1 as h becomes smaller. Therefore, the denominator of the second limit gets close to a value of 2 as h gets close to 0. The sine term within the numerator, on the other hand, attains a value of 0 as h approaches 0. This drives not just the second limit, but also the entire product limit to 0:

Bringing everything together, we can at last come to the subsequent conclusion:

This, ultimately informs us that the derivative of sin x is merely cos x.

The Derivative of the Cosine Function

Likewise, we can calculate the derivative of the cosine function by re-leveraging the know-how hat we have obtained in identifying the derivative of the sine function. Replacing for f(x) = cos x:

The addition formula is now leveraged to expand the cos(x+h) term as follows:

Cos(x+y) = cos x cos y + sin x sin y

Which again leads us to the summation of two limits.

We can swiftly realize that we have already assessed these two limits in the process of identifying the derivative of sine, the first limit gets close to 1, whereas the second limit approaches 0, as the value of h gets smaller.

cos’(x) = (1) (-sin x) + (0) (cos x)

cos’(x) = -sin x

Which, basically informs us that the derivative of cos x is conversely -sin x.

The criticality of the derivatives that we have just discovered lies in their way of defining the rate of change of the function being considered, at some specific angle, h. For example, if we had to recount the graph of the periodic sine function, we can see that its first positive peak coincides with an angle of π / 2 radians.

We can leverage the derivative of the sine function in order to compute directly the rate of change, or slope, of the tangent line at this peak on the graph.

sin’(π / 2) = cos(π / 2) = 0

We discover that this outcome correlates well with the fact that the peak of the sine function is, indeed a stationary point with nil rate of change.

A somewhat samey exercise can be simple to carry out to compute the rate of change of the tangent line at differing angles, for both the sine and cosine functions.

Identifying derivatives in Python

In this part of the blog post, we will be identifying the derivatives of the sine and cosine functions in Python.

For this reason, we will be leveraging the SymPy library, which will facilitate us in dealing with the computation of mathematical objects symbolically. This implies that the SymPy library will allow us to define and manipulate the sine and cosine functions, with unassessed variables, in symbolic format. We will be able to define a variable as symbol by leveraging symbols in Python, whereas to take the derivatives we shall be leveraging the diff function.

 1234 from sympy import difffrom sympy import sinfrom sympy import cosfrom sympy import symbols

We can now move forward and go about defining a variable x in symbolic format, which implies that we can work with x without the need to assign it a value.

# define variable as symbol

x = symbols(‘x’)

Following this, we can identify the derivative of the sine and cosine function with regards to x, leveraging the diff function.

 123 # find the first derivative of sine and cosine with respect to xprint(‘The first derivative of sine is:’, diff(sin(x), x))print(‘The first derivative of cosine is:’, diff(cos(x), x))

We find out that the diff function correctly returns cos(x) as the derivative of sine, and -sin(x) as the derivative of cosine.

Python

 12 The first derivative of sine is: cos(x)The first derivative of cosine is: -sin(x)

The diff function can take several derivatives too. For instance, we can identify the second derivative for both sine and cosine by passing x twice.

 123 # find the second derivative of sine and cosine with respect to xprint(‘The second derivative of sine is:’, diff(sin(x), x, x))print(‘The second derivative of cosine is:’, diff(cos(x), x, x))

This implies that, in discovering the second derivative, we are taking the derivative of the derivative of every function. For instance, to identify the second derivative of the sine function, we take the derivative of cos(x), its first derivative. We can go about identifying the second derivative with regards to the cosine function by likewise taking the derivative of -sin(x), its first derivative.

The second derivative of sine is: -sin(x)

The second derivative of cosine is: -cos(x)

We can, alternatively pass the number 2 to the diff function to signify that we are interested in identifying the second derivative.

 123 # find the second derivative of sine and cosine with respect to xprint(‘The second derivative of sine is:’, diff(sin(x), x, 2))print(‘The second derivative of cosine is:’, diff(cos(x), x, 2))

Inputting all of this together, the total instance example of identifying the derivative of the sine and cosine functions is detailed below:

 1234567891011121314151617181920 # finding the derivative of the sine and cosine functionsfrom sympy import difffrom sympy import sinfrom sympy import cosfrom sympy import symbols # define variable as symbolx = symbols(‘x’) # find the first derivative of sine and cosine with respect to xprint(‘The first derivative of sine is:’, diff(sin(x), x))print(‘The first derivative of cosine is:’, diff(cos(x), x)) # find the second derivative of sine and cosine with respect to xprint(‘\nThe second derivative of sine is:’, diff(sin(x), x, x))print(‘The second derivative of cosine is:’, diff(cos(x), x, x)) # find the second derivative of sine and cosine with respect to xprint(‘\nThe second derivative of sine is:’, diff(sin(x), x, 2))print(‘The second derivative of cosine is:’, diff(cos(x), x, 2))

Conclusion

In this guide, you learned how to identify the derivative of the sine and cosine functions.

Particularly, you are now aware of:

• How to identify the derivative of the sine and cosine functions through application of various rules from algebra, trigonometry, and limits.
• How to identify the derivative of the sine and cosine functions in Python.