COS Function – Calc Cosine of Angle – Excel, VBA, G Sheets
Written by
Reviewed by
Download the example workbook
This tutorial demonstrates how to use the COS Function in Excel to calculate the cosine.
COS Function Overview
The COS function calculates the cosine of an angle in radians.
Create a Cosine Curve
To create a cosine curve in Excel, we need to first choose our start and end points and then list out a lot of numbers. Let’s go from -2π up to 2π in increments of 0.1.
=COS(C3)
Next, we’re going to add the 0.1 onto the angle and then calculate the cosine of that angle. Use the formula:
=C3+$G$2
(the $ signs lock G2 so the formula will always reference that 0.1 even if we copy the formula!)
Now highlight both the new angle and cosine function that we’ve calculated, hold the handle, and drag it down until our angle reaches about 2π (about 6.28)
Highlight the entire range of both angles and cosines, click insert, find the graphs and select “Scatter with Smooth Lines”.
Manipulating the cosine curve
Trigonometric curves can be manipulated in a few ways – vertical shift (shifting the curve up and down on the graph), phase shift (shifting the curve left and right), amplitude modulation (how high and low the peaks and troughs are), and wavelength/period modulation (how far along the x-axis the curve is stretched or compressed).
While we won’t go in depth about each of these, here are the basic ways to manipulate each of these. Keep an eye on the formula bar in the examples to see how it changes the curve compared to the original curve.
- Vertical shifting – Add a number after the function
=COS(number)+verticalShift
2. Phase shifting – Add a number inside the argument of the function
=COS(number+phaseShift)
3. Amplitude modulation – Multiply the function by a number
4. Wavelength modulation – Multiply the argument by a number
COS in Google Sheets
The COS Function works exactly the same in Google Sheets as in Excel:
COS Examples in VBA
You can also use the COS function in VBA. Type:
Dim val1 as double
val1 = cos(number)