Trapezium rule #2

  • Follow


Hi,

I've been working on this problem for quite a while but really not sure whether my approach is correct. I'm looking to create an mfile to perform to an integral using the trapezoidal rule where the strip length will increase geometrically such that

(delta) xn = r^(n-1) * (delta) x1
where r could be the constant and (delta) xn is the width of the nth strip

This is the code i've got so far:

r=input('Input r');
a=(100.*(1-r))/(1-(r.^100));
b=1;
T=0;
for n=1:100
    x=(r.^(n-1)).*a;
    A=((1/b)+(1/(b+x))).*x.*0.5;
    T=T+A;
    b=b+x;
end
disp(T)

NB I've used the sum of the geometric progression to calculate (delta) x1 

To me it seems a bit simple but is this as effective. Could there be a better method? or perhaps a function that does the job quicker?

Any advice or help would be greatly appreciated! 

Thank you!
0
Reply Azara 1/13/2011 3:51:04 PM

"Azara " <azara.2009@yahoo.co.uk> wrote in message <ign718$vi$1@fred.mathworks.com>...
> Hi,
> 
> I've been working on this problem for quite a while but really not sure whether my approach is correct. I'm looking to create an mfile to perform to an integral using the trapezoidal rule where the strip length will increase geometrically such that
> 
> (delta) xn = r^(n-1) * (delta) x1
> where r could be the constant and (delta) xn is the width of the nth strip
> 
> This is the code i've got so far:
> 
> r=input('Input r');
> a=(100.*(1-r))/(1-(r.^100));
> b=1;
> T=0;
> for n=1:100
>     x=(r.^(n-1)).*a;
>     A=((1/b)+(1/(b+x))).*x.*0.5;
>     T=T+A;
>     b=b+x;
> end
> disp(T)
> 
> NB I've used the sum of the geometric progression to calculate (delta) x1 
> 
> To me it seems a bit simple but is this as effective. Could there be a better method? or perhaps a function that does the job quicker?
> 
> Any advice or help would be greatly appreciated! 
> 
> Thank you!

The trapezoidal rule is already implemented in matlab

doc trapz
doc cumtrapz
0
Reply Paulo 1/13/2011 4:18:05 PM


1 Replies
331 Views

(page loaded in 0.023 seconds)

Similiar Articles:













7/22/2012 6:59:16 AM


Reply: