📄 trapc.m
字号:
function [Itpc]=trapc(a,b,M,f,choice,varargin)%TRAPC Composite two-points numerical integration.% ITPC = TRAPC(A,B,M,FUN,CHOICE) computes an approximation of the integral % of the function FUN via the trapezoidal method (with M equispaced intervals)% if CHOICE=1, via the Gauss composite formula if CHOICE=2.% FUN accepts real scalar input x and returns a real scalar% value. FUN can also be an inline object.H=(b-a)/M;switch choice case 1, x=linspace(a,b,M+1); fpm=feval(f,x,varargin{:}); fpm(2:end-1)=2*fpm(2:end-1); Itpc=0.5*H*sum(fpm);case 2, z=linspace(a,b,M+1); x=z(1:end-1)+H/2*(1-1/sqrt(3)); x=[x, x+H/sqrt(3)]; fpm=feval(f,x,varargin{:}); Itpc=0.5*H*sum(fpm);otherwise disp('Unknown formula');endreturn
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -