From: Kara Charaziak on
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?
From: Steven Lord on

"Kara Charaziak" <pink03(a)o2.pl> wrote in message
news:i0ahd8$lem$1(a)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(a)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


From: Kara on
"Steven Lord" <slord(a)mathworks.com> wrote in message <i0akqt$b2o$1(a)fred.mathworks.com>...
>
> "Kara Charaziak" <pink03(a)o2.pl> wrote in message
> news:i0ahd8$lem$1(a)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(a)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 :)