-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
260 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,260 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "e630c395-5419-4786-84fe-94bc0f0abbdc", | ||
"metadata": {}, | ||
"source": [ | ||
"# Sine Trigonometry" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "76d06808-871e-424f-b5d6-7679bf4a92a4", | ||
"metadata": {}, | ||
"source": [ | ||
"---" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "b369aa9f-bc82-4d84-9390-c8fed479b9c6", | ||
"metadata": {}, | ||
"source": [ | ||
"## Overview\n", | ||
"\n", | ||
"Sine is a trigonometric function equal to the opposite side of a right triangle and divided by the hypotenuse\n", | ||
"\n", | ||
"```\n", | ||
"sin(Θ) = length of opposite side / length of hypotenuse\n", | ||
"```" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "0725f24c-2edd-4f96-aa85-d871a5457748", | ||
"metadata": {}, | ||
"source": [ | ||
"## [sine in NCL](https://www.ncl.ucar.edu/Document/Functions/Built-in/sin.shtml)\n", | ||
"\n", | ||
"```\n", | ||
"function sin (\n", | ||
"\tvalue : numeric \n", | ||
")\n", | ||
"\n", | ||
"Return value [dimsizes(value)] as float or double\n", | ||
"```\n", | ||
"### Input Values\n", | ||
"Input value of one or more values of any dimension (in radians)\n", | ||
"\n", | ||
"### Return Value\n", | ||
"Returns an array dimensioned the same as the input value. The return type is double if the input is double, and float otherwise\n", | ||
"\n", | ||
"### NCL Example:\n", | ||
"```\n", | ||
"sin_f = sin(0.5)\n", | ||
"print(sin_f)\n", | ||
"```\n", | ||
"Returned value is 0.4794255" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "0d460cdf-cf91-4ad4-8ea1-872a15cc2926", | ||
"metadata": {}, | ||
"source": [ | ||
"## Sine in Python\n", | ||
"\n", | ||
"Sine is both a built-in function in Python (that requires no additional packages) as well as part of the common Python package Numpy\n", | ||
"\n", | ||
"- Built-in Math Function\n", | ||
"- Numpy Sine Function" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "fd87eed0-c2ea-4b7c-97c4-1f8f0bc22c6a", | ||
"metadata": {}, | ||
"source": [ | ||
"## [Built-In Math Function](https://docs.python.org/3/library/math.html#math.sin)\n", | ||
"\n", | ||
"When working with sine in Python, the input value is in radians\n", | ||
"\n", | ||
"- Input: single input values (float, decimals, integars)\n", | ||
"- Returns: the sine of inputs in radians" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"id": "6966eb6b-1861-4084-bcf9-9fe91c75aa3e", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"0.479425538604203\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import math\n", | ||
"\n", | ||
"value = 0.5 # radians\n", | ||
"math_sin_value = math.sin(value)\n", | ||
"print(math_sin_value)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "42cd2476-00a3-4f29-a8be-ab19af9f5c69", | ||
"metadata": {}, | ||
"source": [ | ||
"## [Numpy Sine Value](https://numpy.org/doc/stable/reference/generated/numpy.sin.html)\n", | ||
"\n", | ||
"When working with sine in Numpy, the input value is in radians. One advantage of working with numpy is working with more than a single input. Numpy accepts input values of floats, decimals, and arrays.\n", | ||
"\n", | ||
"Numpy input: array_list values (floats, integars, arrays, lists, etc..)\n", | ||
"\n", | ||
"Returns: the sine of each element of the input in radians" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 11, | ||
"id": "e6352b3b-57c1-456c-806f-39fc132d2a1d", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"0.479425538604203\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# Input: Single Value\n", | ||
"import numpy as np\n", | ||
"\n", | ||
"value = 0.5 # radians\n", | ||
"np_sin_value = np.sin(value)\n", | ||
"print(np_sin_value)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 12, | ||
"id": "c4e73813-067c-425d-8a31-35d894d9e199", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[0.47942554 0.84147098 0.99749499]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# Input: List\n", | ||
"import numpy as np\n", | ||
"\n", | ||
"values = [0.5, 1.0, 1.5]\n", | ||
"np_sin_list_values = np.sin(values)\n", | ||
"print(np_sin_list_values)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 13, | ||
"id": "5008e1ac-4988-41e5-bef3-4d60fce22ef8", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"[0.47942554 0.84147098 0.99749499]\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# Input: Array\n", | ||
"import numpy as np\n", | ||
"\n", | ||
"values = np.array([0.5, 1.0, 1.5])\n", | ||
"np_sin_array_values = np.sin(values)\n", | ||
"print(np_sin_array_values)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "599bffbb-4220-4640-b667-ac892585017d", | ||
"metadata": {}, | ||
"source": [ | ||
"## Helpful Tip\n", | ||
"\n", | ||
"Convert from degrees to radians and radians to degrees with Numpy functions\n", | ||
"\n", | ||
"- [np.rad2deg](https://numpy.org/doc/stable/reference/generated/numpy.rad2deg.html): Convert angles from radians to degrees\n", | ||
"- [np.deg2rad]((https://numpy.org/doc/stable/reference/generated/numpy.deg2rad.html): Convert angles from degrees to radians" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 14, | ||
"id": "a496ad9d-d54a-42e1-a25b-370e6f646706", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"0.6108652381980153\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# sine requires a value in radians\n", | ||
"value_in_degrees = 35 # degrees\n", | ||
"value_in_radians = np.deg2rad(value_in_degrees)\n", | ||
"print(value_in_radians) # radians" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "ea71d621-707b-402a-83b7-b72b87cdc869", | ||
"metadata": {}, | ||
"source": [ | ||
"## Further Reading\n", | ||
"\n", | ||
"- [Built-in sine math function](https://docs.python.org/3/library/math.html#math.sin)\n", | ||
"- [Numpy sine function](https://numpy.org/doc/stable/reference/generated/numpy.sin.html)\n", | ||
"- [NCL sine function](https://www.ncl.ucar.edu/Document/Functions/Built-in/sin.shtml)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.8" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |