|
|
function trapz
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: Trapezoidal Rule in MATLAB. - comp.soft-sys.matlabHi, I'm trying to integrate the following function: 20/(1+x^2) in MATLAB using the trapezoidal rule ( not using the Matlab function 'trapz'). ... Help with discrete double integral - comp.soft-sys.matlab ...Of course you must realize that this double trapz scheme cannot achieve the same accuracy as quad2d for explicitly defined functions since the latter has unlimited access ... Double integral with bessel function and summation - comp.soft-sys ...I tried nested trapz functions so far (I didn't succeed here, but I guess it would be possible) and the dblquad function. My code seems to work with the dblquad ... phase modulation in MATLAB - comp.soft-sys.matlabPart of my code: energy_in=trapz(trapz(function)) ff=fft2(function,1024,1024); ff2=fftshift(ff); re=real(ff2); im=imag(ff2); amp=sqrt(re.^2+im.^2);%abs(ff2 ... Trapezium rule - comp.soft-sys.matlabCould there be a better method? or perhaps a function that does the job quicker? ... 20/(1+x^2) in MATLAB using the trapezoidal rule ( not using the Matlab function 'trapz'). ... Finding x & y points from graphs - comp.soft-sys.matlabHow do i plot this on a graph and find the area under the curve? Do i use 'trapz ... soft-sys.matlab Stationary point of curve - comp.soft-sys.matlab I have a function, f ... comp.soft-sys.matlab - page 260plz help... #2 1 2 (12/18/2003 7:56:29 PM) hi, all, I have to write a MATLAB code to solve an eqn using the numerical integration function trapz. the eqn is like this.. Trapezium Rule with Varying Strip Widths - comp.soft-sys.matlab ...Any suggestions/help would be very much appreciated So why would your function not just call trapz, with points at a varying distance? Ok, I assume that as part ... Trapezium rule - comp.soft-sys.matlab... MATLAB. - comp.soft-sys.matlab Hi, I'm trying to integrate the following function: 20/(1+x^2) in MATLAB using the trapezoidal rule ( not using the Matlab function 'trapz'). ... ??? Output argument "r" (and maybe others) not assigned during ...... ds)); c_3=(X_half-X(d)).^2+(Y_half-Y(d)).^2; r=pi*E_x(d)-trapz(s ... It's odd, the function only bombs out when the maximum value for the row appears, when ... trapz - Trapezoidal numerical integrationThis MATLAB function computes an approximation of the integral of Y via the trapezoidal method (with unit spacing). trapz (MathScript Function) - NI LabVIEW 8.6 HelpName: Description: x: Specifies the x-values of the function you want to integrate. x is a real vector. y: Specifies the y-values of the function you want to integrate. 7/14/2012 8:13:43 PM
|
|
|
|
|
|
|
|
|