I have some experimental time traces to integrate. CUMTRAPZ seems
to be a simple and easy option for me. To test it, I tried to integrate a
simple SIN(X) time trace as follows,
x = 0:pi/100:4*pi];
y = sin( 2*pi*x).
inty = cumtrapz( x', y' );
I would expect a COS(X) time trace after CUMTRAPZ. The integrated
time trace gave a cos pattern of variation, correct amplitude BUT was
wrong in phase and shifted upwards, i.e. it is greater than zero for all
x and gives 0, rather than 1, at x = 0. I am very confused with the
results.
Do I need to pay special care in working with CUMTRAPZ, or it doesn't
serve my purpose? If the latter is true, could you recommend me
some other routines?
Thanks.
Randolph.
--
Posted from [216.201.19.6]
via Mailgate.ORG Server - http://www.Mailgate.ORG
Running this code:
x = 0:pi/100:4*pi;
y = sin( 2*pi*x);
inty = cumtrapz(x',y');
plot(x,y,x,inty)
produces a plot that looks right to me. You wrote:
> I would expect a COS(X) time trace after CUMTRAPZ. The integrated
> time trace gave a cos pattern of variation, correct amplitude BUT was
> wrong in phase and shifted upwards, i.e. it is greater than zero for all
> x and gives 0, rather than 1, at x = 0. I am very confused with the
> results.
CUMTRAPZ is the cumulative integral, or the running sum of the area
under the curve. From the graph above, you can see that the running sum
of the area is never negative, at the lowest it's zero. As for the
value at x=0, there's no area under the curve yet, so the value of 0 is
correct.
If you work it out by hand, you'll should be able to verify the results.
-- Nabeel
It seems you may be forgetting a bit of your calculus. You are numerically
taking the INDEFINITE integral of your function. In that case, you must be
prepared to add a constant to your solution. [I think it is really only
shifted "upward", and not really wrong in phase.] You need to determine the
appropriate constant from other conditions of your problem.
Tim