Using the definition of the natural logarithmic function, we have:
ln(x) = ∫(1, x) dt/t where 1<= x
We want to evaluate ln(5.6) using riemann sum
Let n be the number of sub-intervals, then the width of each sub-interval is ∆x = (5.6 - 1)/n = 4.6/n
Let ti be the left endpoint of the i-th sub-interval, then ti = 1 + i∆x
Let si be the value of 1/ti in the i-th sub-interval, then si = 1/ti
Then, we can approximate ln(5.6) as follows:
ln(5.6) ≈ (∆x)[s1 + s2 + s3 + ... + sn]
Now, we implement this in MATLAB:
main.m434 chars17 lines
When we run this code, we get:
main.m118 chars3 lines
We can see that the approximate value is very close to the true value. As we increase the value of n, we can get even closer approximations.
gistlibby LogSnag