Numerical integration¶
The antiderivative of \(e^x\) is, of course, itself. That makes evaluation of \(\int_0^1 e^x\,dx\) by the Fundamental Theorem trivial.
using FundamentalsNumericalComputation
exact = exp(1)-1
1.718281828459045
The Julia package QuadGK
has a good all-purpose numerical integrator that estimates the value numerically without finding the antiderivative first. As you can see here, it’s often just as accurate.
Q,errest = quadgk(x->exp(x),0,1)
@show Q;
Q = 1.718281828459045
The numerical approach is far more robust. For example, \(e^{\sin x}\) has no useful antiderivative. But numerically it’s no more difficult.
Q,errest = quadgk(x->exp(sin(x)),0,1)
@show Q;
Q = 1.6318696084180515
When you look at the graphs of these functions, what’s remarkable is that one of these areas is the most basic calculus while the other is almost impenetrable analytically. From a numerical standpoint, they are practically the same problem.
plot([exp,x->exp(sin(x))],0,1,fill=0,leg=:none,
ylabel=["exp(x)" "exp(sin(x))"],ylim=[0,2.7],layout=(2,1))