function trapz

  • Follow


Hi all,
I want to calculate area under the curve and I figured out that trapz is the function I need. However I got strange results with it.
So I have a curve (looks like a bandpass filter) y [y1,y2,..yn] for given values x [x1..xn]. to get more data points I use interp1 and depending on that how many new points I generate with interp1 (so how 'dense' the curve is) i got very different results from trapz(y). I don't get it, especially that the values I got are very big - bigger than I expected them to be. what I am doing wrong? 
0
Reply Kara 6/28/2010 4:08:08 PM

"Kara Charaziak" <pink03@o2.pl> wrote in message 
news:i0ahd8$lem$1@fred.mathworks.com...
> Hi all,
> I want to calculate area under the curve and I figured out that trapz is 
> the function I need. However I got strange results with it.
> So I have a curve (looks like a bandpass filter) y [y1,y2,..yn] for given 
> values x [x1..xn]. to get more data points I use interp1 and depending on 
> that how many new points I generate with interp1 (so how 'dense' the curve 
> is) i got very different results from trapz(y). I don't get it, especially 
> that the values I got are very big - bigger than I expected them to be. 
> what I am doing wrong?

Hint:

x1 = 1:3;
x2 = 10*x1;
y = [0 1 0];
Area1 = trapz(y)
Area2 = trapz(x1, y)
Area3 = trapz(x2, y)

What does the HELP for TRAPZ indicate it uses for the spacing between the 
points in the case where you call it with one input?
How does that spacing affect the value returned by TRAPZ?
Why?

-- 
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on 
http://www.mathworks.com 


0
Reply slord (13267) 6/28/2010 5:06:40 PM


"Steven Lord" <slord@mathworks.com> wrote in message <i0akqt$b2o$1@fred.mathworks.com>...
> 
> "Kara Charaziak" <pink03@o2.pl> wrote in message 
> news:i0ahd8$lem$1@fred.mathworks.com...
> > Hi all,
> > I want to calculate area under the curve and I figured out that trapz is 
> > the function I need. However I got strange results with it.
> > So I have a curve (looks like a bandpass filter) y [y1,y2,..yn] for given 
> > values x [x1..xn]. to get more data points I use interp1 and depending on 
> > that how many new points I generate with interp1 (so how 'dense' the curve 
> > is) i got very different results from trapz(y). I don't get it, especially 
> > that the values I got are very big - bigger than I expected them to be. 
> > what I am doing wrong?
> 
> Hint:
> 
> x1 = 1:3;
> x2 = 10*x1;
> y = [0 1 0];
> Area1 = trapz(y)
> Area2 = trapz(x1, y)
> Area3 = trapz(x2, y)
> 
> What does the HELP for TRAPZ indicate it uses for the spacing between the 
> points in the case where you call it with one input?
> How does that spacing affect the value returned by TRAPZ?
> Why?
> 
> -- 
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
> To contact Technical Support use the Contact Us link on 
> http://www.mathworks.com 
> 

Thank you so much! now I got it :) 
0
Reply Kara 6/28/2010 7:21:04 PM

2 Replies
163 Views

(page loaded in 2.89 seconds)

Similiar Articles:













7/14/2012 8:13:43 PM


Reply: