In order to use Riemann sum to compute the integral of the function f(x)=sin(x*cos(x))
between x=4
and x=6
, we need to perform the following steps:
Define the integral limits.
Define the number of sub-intervals to partition the integral.
Compute the increment width for each sub-interval.
Evaluate the function f(x)=sin(x*cos(x))
at each of the partition points.
Multiply the function values with their increments and sum up.
Display the result.
Here's the Matlab code to accomplish it:
main.m450 chars22 lines
The output will be:
main.m80 chars2 lines
Note that the result is only an approximation since it uses Riemann sum method. The accuracy can be increased by increasing the number of sub-intervals n
.
gistlibby LogSnag