Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from mpmath import mp
- # Use 50 decimal digits of precision
- mp.dps = 50
- # Print with 10 digits of precision
- out_prec = 10
- def func(x):
- return mp.e - x * x * mp.exp(x)
- def inv_func(y, sign, k):
- return 2 * mp.lambertw(sign * mp.sqrt(mp.e - y) / 2, k=k)
- r = mp.mpf('.1')
- for i in range(-25, 15):
- x = i * r
- y = func(x)
- # Determine which square root and branch of the Lambert W
- # function we need to get back the x we started with
- if x < -2:
- sign, k = -1, -1
- elif -2 <= x < 0:
- sign, k = -1, 0
- else:
- sign, k = 1, 0
- xx = inv_func(y, sign, k)
- print(x, mp.nstr(y, n=out_prec), mp.nstr(xx, n=out_prec))
- -2.5 2.205250587 -2.5
- -2.4 2.195746418 -2.4
- -2.3 2.187912545 -2.3
- -2.2 2.181994542 -2.2
- -2.1 2.17824898 -2.1
- -2.0 2.176940696 -2.0
- -1.9 2.178339113 -1.9
- -1.8 2.182713431 -1.8
- -1.7 2.190326444 -1.7
- -1.6 2.201426742 -1.6
- -1.5 2.216238968 -1.5
- -1.4 2.234951779 -1.4
- -1.3 2.257703098 -1.3
- -1.2 2.284562163 -1.2
- -1.1 2.315507817 -1.1
- -1.0 2.350402387 -1.0
- -0.9 2.388960404 -0.9
- -0.8 2.430711291 -0.8
- -0.7 2.47495503 -0.7
- -0.6 2.520709639 -0.6
- -0.5 2.566649164 -0.5
- -0.4 2.611030621 -0.4
- -0.3 2.651608189 -0.3
- -0.2 2.685532598 -0.2
- -0.1 2.709233454 -0.1
- 0.0 2.718281828 0.0
- 0.1 2.707230119 0.1
- 0.2 2.669425718 0.2
- 0.3 2.596794536 0.3
- 0.4 2.479589877 0.4
- 0.5 2.306101511 0.5
- 0.6 2.06231906 0.6
- 0.7 1.731543002 0.7
- 0.8 1.293935634 0.8
- 0.9 0.7260033084 0.9
- 1.0 0.0 1.0
- 1.1 -0.9167590605 1.1
- 1.2 -2.06268654 1.2
- 1.3 -3.48282954 1.3
- 1.4 -5.229910107 1.4
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement