Romberg积分法(MATLAB)

% fprintf('请输入区间最小值:\n')
% a=input('');
% fprintf('请输入区间最大值:\n')
% b=input('');
% fprintf('请输入N:\n')
% N = input('');
% fprintf('请输入精度:\n')
% ac = input('');
a=0;
b=1;
N=25;
ac=0.000001;
T = [];
S = [];
C = [];
R = [];
T1=0;
T2=0;
S1=0;
S2=0;
C1=0;
C2=0;
R1=0;
R2=0;
tol = 0;
t = 0;
m=1;
n=1;
h =(b-a)/n;
T1 = h*(fun_rom(b)-fun_rom(a))/2;
T(1)=T1;
n=2;
h =(b-a)/n;
% i = 2;
for i=2:N
% while tol=N
%            break;
%         end
        i=i+1;
end

函数

function y=fun_rom(x)
% y = exp(x)*(x^2);
% y= exp(x)*sin(x);
% y = 4/(1+x^2);
% y = 1/(x+1);
% y=sin(x)/x;
y=cos(x)/((1-x)^2);
% y=cos(x)/(1-x)^2;
% y=(cos(x)/(1-x))^2;
end

你可能感兴趣的:(数值分析作业)