Mikro Step
Kıdemli Üye
- Katılım
- 25 Eylül 2022
- Mesajlar
- 5,895
Son düzenleme:
[ta@bonsai ~]$ python3
Python 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mpmath
>>> mpmath.mp.dps = 500
>>> print(mpmath.mp.pi)
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491
>>>
#!/usr/bin/python3
import mpmath
# Set the precision to 100 digits
mpmath.mp.dps = 100
# Define the angle in radians
angle_radians = mpmath.mpf('0.1') # Example angle
# Taylor series calculation of sine
def sine_taylor_series(x, n_terms=20):
sine = 0
for n in range(n_terms):
term = ((-1)**n) * (x**(2*n + 1)) / mpmath.factorial(2*n + 1)
sine += term
return sine
# Calculate sine using the Taylor series
sine_taylor = sine_taylor_series(angle_radians)
# Calculate sine using mpmath's sine function for comparison
sine_mpmath = mpmath.sin(angle_radians)
print(sine_taylor)
print(sine_mpmath)
[ta@bonsai ~]$ ./a.py
0.09983341664682815230681419841062202698991538801798225999276686156165174428329242760966244350513360876
0.09983341664682815230681419841062202698991538801798225999276686156165174428329242760966244380406303627
[ta@bonsai ~]$
[