dc, 125 bytes
15k?ddsk1-A 5^*sw1sn0[A 5^ln+_1^+ln1+dsnlw!<y]syr1<y1lk/*sz[si1[li*li1-dsi0<p]spli0<p]so0dsw[lzlw^lwlox/+lw1+dswA 2^!<b]dsbxp
Unlike the other dc answer, this works for all real x
greater than or equal to 1 (1 ≤ x
). Accurate to 4-5 places after the decimal.
I would have included a TIO link here, but for some reason this throws a segmentation fault with the version there (dc 1.3
) whereas it does not with my local version (dc 1.3.95
).
###Explanation
As dc
does not support raising numbers to non-integer exponents to calculate x^(1/x)
, this takes advantage of the fact that:
So, to calculate ln(x)
, this also takes advantage of the fact that:
whose definite integral from 1 to (b = x)
is numerically-approximated in increments of 10^-5
using the following Riemann summation formula:
The resulting sum is then multiplied by 1/x
to get ln(x)/x
. e^(ln(x)/x)
is then finally calculated using the e^x
Maclaurin Series to 100 terms as follows:
This results in our relatively accurate output of x^(1/x)
.