the-honk/languages/python/calculators/Trigometric Functions.py

57 lines
1.7 KiB
Python
Raw Normal View History

2022-05-08 12:08:11 +00:00
from cmath import e, pi, sqrt, log
2021-12-27 01:54:37 +00:00
from _helpers import floatInput
2022-05-08 02:13:33 +00:00
i = sqrt(-1)
2021-12-27 01:54:37 +00:00
2022-05-08 02:13:33 +00:00
compute = lambda numerator, denominator: (numerator / denominator).real
2022-05-08 12:08:11 +00:00
computeInverse = lambda x: (-i * log(x, e)).real
2022-05-08 03:21:06 +00:00
2022-05-08 02:13:33 +00:00
sin = lambda x: compute(pow(e, i * x) - pow(e, -i * x), 2 * i)
cos = lambda x: compute(pow(e, i * x) + pow(e, -i * x), 2)
tan = lambda x: compute(pow(e, i * x) - pow(e, -i * x), i * (pow(e, i * x) + pow(e, -i * x)))
2022-05-08 03:21:06 +00:00
csc = lambda x: 1 / sin(x)
sec = lambda x: 1 / cos(x)
cot = lambda x: 1 / tan(x)
2022-05-08 12:08:11 +00:00
arcsin = lambda x: computeInverse((i * x) + sqrt(1 - pow(x, 2)))
arccos = lambda x: computeInverse(x + sqrt(pow(x, 2) - 1))
arctan = lambda x: computeInverse((i - x) / (i + x)) / 2
arccsc = lambda x: computeInverse((pow(x, -1) * i) + sqrt(1 - pow(x, -2)))
arcsec = lambda x: computeInverse((pow(x, -1)) + sqrt(pow(x, -2) - 1))
arccot = lambda x: computeInverse((x + i) / (x - i)) / 2
2022-05-08 03:21:06 +00:00
2022-05-08 12:08:11 +00:00
# todo: hyperbolic functions
# todo: hyperbolic inverse functions
# todo: hyperbolic reciprocal functions
# todo: hyperbolic inverse reciprocal functions
2022-05-08 03:21:06 +00:00
2022-05-08 02:13:33 +00:00
radians = floatInput("Please enter an amount of radians: ")
2021-12-27 01:54:37 +00:00
2022-05-08 02:13:33 +00:00
print(f"""
2022-05-08 03:21:06 +00:00
Trigometric functions
sin({radians}) = {sin(radians)}
2022-05-08 02:13:33 +00:00
cos({radians}) = {cos(radians)}
tan({radians}) = {tan(radians)}
2021-12-27 01:54:37 +00:00
2022-05-08 03:21:06 +00:00
Reciprocal trigometric functions
csc({radians}) = {csc(radians)}
sec({radians}) = {sec(radians)}
cot({radians}) = {cot(radians)}
Inverse trigometric functions
arcsin({sin(radians)}) = {arcsin(sin(radians))}
arccos({cos(radians)}) = {arccos(cos(radians))}
arctan({tan(radians)}) = {arctan(tan(radians))}
Inverse reciprocal trigometric functions
arccsc({csc(radians)}) = {arccsc(csc(radians))}
arcsec({sec(radians)}) = {arcsec(sec(radians))}
arccot({cot(radians)}) = {arccot(cot(radians))}""")