Register to reply 
Integrating a Discrete Function in MATLAB 
Share this thread: 
#1
Oct511, 02:14 PM

P: 53

I have a data curve with discrete time points that I imported into MATLAB. The x axis is an array named t:
Essentially I want to integrate the function from zero to one of the time points. I tried using the functions quad and trapz but they seem to return red error messages. The function trapz works when I integrate over the entire curve (trapz(Cp)) but it won't let me specify an integration interval. 


#2
Oct711, 04:56 AM

Sci Advisor
P: 1,724

Trapz implements the trapezoid ruleif this is what you're looking for, that's great (but since you're not putting in the tvalues, you're just getting the sum of x, which may or may not be what you're looking for):
http://www.mathworks.com/help/techdoc/ref/trapz.html If you want to integrate only a portion of the data, put in only a portion of the vectors! For instance, to extract the 1st through 5th values of x, you'd type in: >> extract=x(1:5) More on array indexing (including the colon operator used above): http://www.mathworks.com/help/techdo...41.html#f2428 As per the examples under trapz above, as long as the two input vectors are the same size, trapz should produce somethingnot sure what the error message is, but if you'd post it, we may be able to help you. 


#3
Oct711, 12:41 PM

P: 53

I should have posed the question in a better way... Based on the research I've done I think Simpson's rule is more efficient. I was initially trying to use the quad function:



#4
Oct811, 04:01 AM

Sci Advisor
P: 1,724

Integrating a Discrete Function in MATLAB
The Simpson's rule implementation in MATLAB requires a function handle. Since you have a collection of data points, this won't work. And as you don't have a huge number of datapoints, efficiency isn't terribly relevant.
http://www.mathworks.com/help/techdo...on_handle.html I'd suggest you stick with the trapezoid rule and use the subset extraction method I linked to earlier. 


Register to reply 
Related Discussions  
Integrating with matlab  Mechanical Engineering  0  
Discrete Math or MATLab?  Academic Guidance  6  
Integrating data in Matlab  Math & Science Software  0  
Problems with integrating a function in MATLAB: Inner matrix dimensions must agree  Math & Science Software  4 