Trapezoidal Method

Thread Starter

Kayne

Joined Mar 19, 2009
105
Hi All,

I would like an answer checked that I have found for the following problem.

\[ y = 5 \int^1_0 \frac{1}{1+x^2} dx \]

using

\[ \int^1_0 f(x) dx = (b-a)[\frac{f(a)+f(b)}{2}] \]

\[ 5*((1-0)*[\frac{{\frac{1}{1+0^2}+\frac{1}{1+1^2}}}{2}])\]

\[5*0.75 = 3.75\]

Have I solved this correctly?

I have tried to chack this in matlab with the code below but I am not getting this answer which now I am not sure which is incorrect.

X = 0:0.5:1;
Y = 5*(1./X.^2)
Z = trapz(X,Y)

Thanks for your time
 

Papabravo

Joined Feb 24, 2006
12,385
I think you are supposed to use more than a single trapezoid to approximate the integral. Did you really think one would do the trick?
 

t_n_k

Joined Mar 6, 2009
5,448
Plus your matlab code isn't correct.

For three terms it would be something like .... [I don't use Matlab]

X=0:0.5:1
Y=[5 5 5]./(1+X^2) ---- you missed the addition in your post
Z=trapz(X,Y)

So to compare values for three terms, your pencil & paper method should have the sum of two trapezoidal approximations with limits from [0 to 0.5] and [0.5 to 1]

As Papbravo implies you should probably use several terms to come up with a good approximation to the 'exact' integral.

\[ans=\frac{5\pi}{4}\]

With 11 terms X=[0 0.1 0.2 .... 1.0] I get a value of Z=3.9249075
 
Last edited:
Top