📄 quad2.m
字号:
function ci = quad2(y,x)
% Function computes the numerical approximation to the definite
% integral y dx (corresponding to sum)
% x abscissas
% y ordinates
% If only one input argument is given x=1:1:length(y);
% if given, x must have the same number of rows an y
% and either the same number of columns or 1 column
% (see also cumquad)
% ci = quad2(x,y)
[ny,my]=size(y);
dy=(y(1:ny-1,:)+y(2:ny,:))*0.5;
if (nargin == 2)
[nx,mx]=size(x);
if nx ~= ny
fprintf('ERROR in QUAD1: Input arrays have incompatible dimensions\n')
size(x), size(y)
return
end
dx=diff(x);
if mx == 1
dx=dx(:,ones(my,1));
elseif mx ~= my,
fprintf('ERROR in QUAD1: Input arrays have incompatible dimensions\n')
size(x), size(y)
return
end
else
dx=ones(ny-1,my);
end
ci=sum(dx.*dy);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -