06-07-2012 02:35 PM
I have two columns of data, one is time and the other is velocity. I want to be able to integrate velocity with respect to time, but I can not find a function which will let me do this. Preferably, I'd like to do a cumulative trapezoidal integration, such as the one in Matlab. The function "cumtrapz" does not work the same in mathscript as it does in matlab. The "trapz" function did not seem to integrate the columns in the way that I wanted it to, leaving me with just a number.
Is there any way I can recreate the "cumtrapz" function from Matlab in Mathscript?
Thanks.
06-08-2012 12:39 AM - edited 06-08-2012 12:40 AM
The cumtrapz in MathScript can not accept a time array as input. Then, you have to write your own script to calculate the cumulative trapezoid integration. For example, the following script generates a sin wave and calculates the cumulative trapezoidal integration.
t = 0:0.1:pi; x = sin(t); y = 0.5*(x(1:(end-1))+x(2:end)).*(t(2:end)-t(1:(end-1))); %trapizoidal integration y = cumsum(y); %cumulative sum