NI Home
Cart Cart | Help
Hello Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI
You are here: 
NI Home > NI Developer Zone > NI Discussion Forums


Reply
Member
PumpGuy
Posts: 20
0 Kudos

How do you integrate a column with respect to another column

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.

Active Participant
ttrr
Posts: 225
0 Kudos

回复: How do you integrate a column with respect to another column

[ Edited ]

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

 

 

By using this web site, you accept the Terms of Use for this web site. Please read these Terms of Use carefully before using any part of this site. Please go here for information on ni.com's copyright infringement policy.
My Profile | Privacy | Legal | Contact NI © 2011 National Instruments Corporation. All rights reserved.    |    E-Mail this Page E-Mail this Page