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

51 lines
1.4 KiB
Python
Raw Normal View History

2024-10-09 17:02:46 +00:00
from cmath import e, sqrt, log
2024-10-09 17:02:37 +00:00
from _helpers import floatInput
2024-10-09 17:02:46 +00:00
i = sqrt(-1)
2024-10-09 17:02:37 +00:00
2024-10-09 17:02:46 +00:00
compute = lambda numerator, denominator: (numerator / denominator).real
2024-10-09 17:02:46 +00:00
ln = lambda x: log(x, e)
2024-10-09 17:02:46 +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)))
2024-10-09 17:02:46 +00:00
csc = lambda x: 1 / sin(x)
sec = lambda x: 1 / cos(x)
cot = lambda x: 1 / tan(x)
arcsin = lambda x: (-i * ln((i * x) + sqrt(1 - pow(x, 2)))).real
# todo: finish arc functions
arccos = lambda x: None
arctan = lambda x: None
2024-10-09 17:02:46 +00:00
arccsc = lambda x: (-i * (ln((pow(x, -1) * i) + sqrt(1 - pow(x, -2))))).real
2024-10-09 17:02:46 +00:00
arcsec = lambda x: None
arccot = lambda x: None
2024-10-09 17:02:46 +00:00
radians = floatInput("Please enter an amount of radians: ")
2024-10-09 17:02:37 +00:00
2024-10-09 17:02:46 +00:00
print(f"""
2024-10-09 17:02:46 +00:00
Trigometric functions
sin({radians}) = {sin(radians)}
2024-10-09 17:02:46 +00:00
cos({radians}) = {cos(radians)}
tan({radians}) = {tan(radians)}
2024-10-09 17:02:37 +00:00
2024-10-09 17:02:46 +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))}""")