展开全部
% 自定义函数function y = f(x) y = x/(4+x^2);end% 龙贝格算法function result = romberg(f,a,b,e)h = b-a;k = 0;T(1,1)=(b-a)*(f(a)+f(b))/2;while true k = k+1; sum = 0; for i=1:2:2^k sum = sum + f(a+i*h/2^k); end T(k+1,1) = T(k,1)/2 + (h/2^k)*sum; for i=1:k T(k+1,i+1) = ((4^i)*T(k+1,i)-T(k,i))/(4^i-1); end if abs(T(k+1,1)-T(k,1))