The function ln(x) is defined as the integral of 1/t from 1 to x:
index.tsx37 chars2 lines
We can approximate this integral using a Riemann sum. Let delta_x be the width of each rectangle and let x_i = 1+i*delta_x be the right endpoint of the i-th rectangle. Then, our approximation of ln(x) is:
index.tsx43 chars2 lines
We can implement this in JavaScript as follows:
index.tsx171 chars10 linesNow, we can compare our approximation with the true value of ln(5.6):
index.tsx223 chars5 lines
As we can see, our approximation is very close to the true value of ln(5.6).
gistlibby LogSnag