# Help Computing Intengral

• Jun 9th 2011, 11:23 AM
lilyungn
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
• Jun 9th 2011, 12:14 PM
dwsmith
$\int\frac{1}{x} \ dx=\ln|x| +c$
• Jun 9th 2011, 12:53 PM
lilyungn
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.
• Jun 9th 2011, 01:01 PM
TheEmptySet
Quote:

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

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

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

Now for the left just calculate

$\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 $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