📄 driver.m
字号:
%%% error function%f = inline('exp(-x.^2)*2/sqrt(pi)', 'x');%a = 0; b = 2;%integ_ex = erf(b);% bessel function%f = inline('cos( 8*sin(x) - x )/pi', 'x');%a = 0; b = pi;%integ_ex = bessel(1,8);% %f = inline('4./(1+x.^2)', 'x');%a = 0; b = 1;%integ_ex = pi;% f = inline('sin(x)', 'x');a = 0; b = pi;integ_ex = 2;% %f = inline('atan(10*x)', 'x');%a = -3; b = 4;%integ_ex = 4*atan(40) + 3*atan(-30) - (1/20)*log(16/9);% %f = inline('exp(-50*(x-0.5).^2) + exp(-2*x)', 'x');%a = 0; b = 1;%integ_ex = 1;% %f = inline('sin(x).^2.*cos(x).^4', 'x');%a = 0; b = 2*pi;%integ_ex = b/16;disp(' ')disp(' Use the composite Trapezoidal rule')tol = 1.e-4;[integ, T, nfeval] = trapcomp(f, a, b, tol);fprintf(1,' computed integral %12.8e \n', integ)fprintf(1,' relative error %12.8e \n', abs(integ-integ_ex)/abs(integ_ex) )fprintf(1,' number of function values needed %6d \n', nfeval)disp(' hit return to continue ....'); pausedisp(' ')disp(' Use the composite Simpson rule')tol = 1.e-4;[int, S, nfeval] = simpcomp(f, a, b, tol);fprintf(1,' computed integral %12.8e \n', integ)fprintf(1,' relative error %12.8e \n', abs(integ-integ_ex)/abs(integ_ex) )fprintf(1,' number of function values needed %6d \n', nfeval)disp(' hit return to continue ....'); pausedisp(' ')disp(' Use Romberg integration')tol = 1.e-4;[integ, R, nfeval] = romberg(f, a, b, tol);fprintf(1,' computed integral %12.8e \n', integ)fprintf(1,' relative error %12.8e \n', abs(integ-integ_ex)/abs(integ_ex) )fprintf(1,' number of function values needed %6d \n', nfeval)disp(' hit return to continue ....'); pausedisp(' ')disp(' Use adaptive Simpson integration')tol = 1.e-4;hmin = 1.e-8;[integ, xfv, nfeval] = simpadpt(f, a, b, tol, hmin);fprintf(1,' computed integral %12.8e \n', integ)fprintf(1,' relative error %12.8e \n', abs(integ-integ_ex)/abs(integ_ex) )fprintf(1,' number of function values needed %6d \n', nfeval)fv = feval(f, xfv);plot(xfv, fv, 'o')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -