Hey I was just home early from work today and decided I would put up a port of a numerical analysis project I completed a while back. On Rhomberg Integration is a numerical way of doing integration not as accurate as you would by hand, but you cant tell a computer to get a pen and paper out can you…. wait you probably can… but the fact remains I don’t know how. Anyways I done this the first time around in Matlab but i dont use it any-more due to the fact it costs thousands of pounds to get and therefore i used Octave instead and its very nice i have to say it feels alot like matlab and its proper Free software which is a bonus. Anyways here is the code:
-
#Rhomberg.m
-
#Rhomberg Integration in Ocatave
-
#Not so nicely coded but hey it seems to work and integrate it right
-
#Try Rhomberg(0,pi,8)
-
-
function r = Rhomberg(a,b,n)
-
disp("Rhomberg Integration");
-
-
h=b-a;
-
r(1,1)= h/2*(f(a)+f(b));
-
disp(r);
-
-
for i=2:n
-
tmp=0;
-
for k=1:2^(i-2)
-
tmp += f(a +(k-0.5)*h);
-
endfor
-
r(2,1)=0.5*(r(1,1)+h*tmp);
-
-
for j=2:i
-
ext = ((r(2,j-1)-r(1,j-1))/(4^(j-1)-1));
-
r(2,j) = r(2,j-1) + ext;
-
endfor
-
for j=1:i
-
disp(r(2,j));
-
endfor
-
h=h/2;
-
for j=1:i
-
r(1,j)=r(2,j);
-
endfor
-
endfor
-
format long;
-
#printf("long",r);
-
endfunction
-
-
function s = f(x)
-
s = sin(x);
-
endfunction


