# Thread: Help Computing Intengral

1. ## Help Computing Intengral

I need help computing this integral with the different techniques mentioned below.

∫ 50 1/x dx
1

(thats a 50 at the top and a 1 at the bottom of the integram sign)

- Right rectangular scheme
- Left rectangular scheme
- Midpoint Rectangular scheme
- trapezoid scheme
- Simpson sRule

2. $\displaystyle \int\frac{1}{x} \ dx=\ln|x| +c$

3. More specifically I need to write a code in either Matlab or any other programming language from n = 2, 10, 100, 1000 to compute each method.

4. Originally Posted by lilyungn
I need help computing this integral with the different techniques mentioned below.

∫ 50 1/x dx
1

(thats a 50 at the top and a 1 at the bottom of the integram sign)

- Right rectangular scheme
- Left rectangular scheme
- Midpoint Rectangular scheme
- trapezoid scheme
- Simpson sRule
for the first 2 just use the definition of a Riemann sum.

Here is some pseudo code

$\displaystyle \Delta x =\frac{b-a}{n}$

$\displaystyle x_i=a+i\Delta x$ if you want left end points $\displaystyle i=0,1,2,...,n-2,n-1$ and for right $\displaystyle i=1,2,...,n-1,n$

Now for the left just calculate

$\displaystyle \int_{a}^{b} f(x)dx \approx \Delta x\sum_{i=0}^{n-1}f(x_i)$.

In Matlab would use parameters like a and b and have the function take them as an input. Also if you define your partition as a vector you can have Matlab evaluate all of the $\displaystyle x_i$'s at the same time. Just modify the above to use the other quadrature rules.

Here is a copy of an m file for the left end point

Code:
function [ output ] = LeftEnd(n,a,b )
%Use Left end point to approximate the integral of 1/x from a to b using
% n points.
OneOver=@(x) x.^(-1);
v=zeros(1,n);
for m=1:n
v(1,m)=a+((b-a)/n)*((m-1));
end
y=OneOver(v);
output=((b-a)/n)*sum(y);

end