Trapezoidal Integration

by

 

Simple and intuitive numerical integration based on trapezoidal rule.

int_trapz(X,Ts)
%%Integration
function [out] = int_trapz(X,Ts)
l = length(X);
Y = zeros(l,1);
Y(1) = X(1);
for i=2:1:l
    Y(i) = Y(i-1) + 0.5*Ts*(X(i-1) + X(i));
end
out = Y;
clear -regexp ^r\d{1}$;
clear time;
end
    

Contact us