function Romberg(a,b,n)
h=b-a;
R(1,1)=h*(f(a)+f(b))/2;
for i=2:n
m=0;
for k=1:2^(i-2)
m=m+f(a+(k-0.5)*h);
end
R(2,1)=1/2*(R(1,1)+h*m);
for j=2:i
R(2,j)=R(2,j-1)+(R(2,j-1)-R(1,j-1))/(4^(j-1)-1);
end
h=h/2;
for j=1:i
R(1,j)=R(2,j);
end
end
disp(R(2,3))
end
function f=f(x)
f=x^2*log(x);
end
时间: 2024-10-26 21:35:37