Search code examples
matlabnumerical-integration

Integrate log(x) Matlab


How can 1/ln(x) be integrated in Matlab?

y=0:.1:1;
a=log(y);
plot(a,y);
z=quad(a,-2,2);

I thought this would work.


Solution

  • This works for me:

    z = quad(@(x) 1./log(x), 2, 10)
    

    and gives the result

    z = 5.1204
    

    You can't integrate across the interval -2:2, because the natural logarithm is undefined at x = 0, and at x = 1, the natural logarithm is 0, so the reciprocal isn't defined.