0
0
NumPydata~10 mins

Trigonometric functions (sin, cos, tan) in NumPy - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Trigonometric functions (sin, cos, tan)
Input angle in radians
Calculate sin(angle)
Calculate cos(angle)
Calculate tan(angle)
Output sin, cos, tan values
Start with an angle in radians, then calculate sine, cosine, and tangent values step-by-step, and finally output these values.
Execution Sample
NumPy
import numpy as np
angle = np.pi / 4
sin_val = np.sin(angle)
cos_val = np.cos(angle)
tan_val = np.tan(angle)
print(sin_val, cos_val, tan_val)
Calculate sine, cosine, and tangent of 45 degrees (π/4 radians) using numpy.
Execution Table
StepVariableValueDescription
1angle0.7853981633974483Set angle to π/4 radians (45 degrees)
2sin_val0.7071067811865475Calculate sin(π/4)
3cos_val0.7071067811865476Calculate cos(π/4)
4tan_val0.9999999999999999Calculate tan(π/4)
5output(0.7071, 0.7071, 1.0)Print sin, cos, tan values rounded
💡 All trigonometric functions calculated for the input angle; execution ends.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
angleundefined0.78539816339744830.78539816339744830.78539816339744830.78539816339744830.7853981633974483
sin_valundefinedundefined0.70710678118654750.70710678118654750.70710678118654750.7071067811865475
cos_valundefinedundefinedundefined0.70710678118654760.70710678118654760.7071067811865476
tan_valundefinedundefinedundefinedundefined0.99999999999999990.9999999999999999
Key Moments - 3 Insights
Why do sin(π/4) and cos(π/4) have almost the same value?
Because π/4 radians is 45 degrees, where sine and cosine values are equal, as shown in steps 2 and 3 of the execution_table.
Why is tan(π/4) almost 1 but not exactly 1?
Due to floating-point precision limits in computers, tan(π/4) is very close to 1 but not exactly, as seen in step 4 of the execution_table.
Why must the angle be in radians, not degrees?
Numpy trigonometric functions expect radians. If degrees are used directly, results will be incorrect. Here, angle is set to π/4 radians in step 1.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 2, what is the value of sin_val?
A1.0
B0.5
C0.7071
D0.0
💡 Hint
Check the 'Value' column for sin_val at step 2 in the execution_table.
At which step does the variable tan_val get its value?
AStep 4
BStep 3
CStep 2
DStep 5
💡 Hint
Look for tan_val assignment in the execution_table rows.
If the angle was changed to π/2 radians, what would happen to tan_val in the execution_table?
Atan_val would be 0
Btan_val would be undefined or very large
Ctan_val would be 1
Dtan_val would be negative
💡 Hint
Recall tan(π/2) is undefined; check how tan_val changes in variable_tracker.
Concept Snapshot
Trigonometric functions use angles in radians.
Use numpy.sin(), numpy.cos(), numpy.tan() to get sine, cosine, tangent.
Input angle → calculate sin, cos, tan → output values.
sin(π/4) ≈ cos(π/4) ≈ 0.707, tan(π/4) ≈ 1.
Always convert degrees to radians before using these functions.
Full Transcript
This lesson shows how to calculate sine, cosine, and tangent of an angle using numpy in Python. We start with an angle in radians, here π/4 which is 45 degrees. Then we calculate sin, cos, and tan step-by-step. The values for sin and cos at 45 degrees are about 0.707, and tan is about 1. We track each variable's value as the code runs. Common confusions include why sin and cos are equal at 45 degrees, why tan is close but not exactly 1, and why angles must be in radians. The quiz tests understanding of these values and behavior. This helps beginners see how trigonometric functions work in code with real numbers.