Windy Day
Windy Day

Reputation: 173

How to do cumulative trapezoidal integration in MATLAB keeping the origin in the centre?

I have vectors top, bottom, mid which I am trying to integrate wrt i, keeping the origin at index 11.

i=0:0.01e-06:1.3e-06;
bottom=cumtrapz(i(11:end),b(11:end));
top=cumtrapz(i(11:end),t(11:end));
mid=cumtrapz(i(11:end),m(11:end));

bottom1=cumtrapz(i(1:11),b(1:11));
top1=cumtrapz(i(1:11),t(1:11));
mid1=cumtrapz(i(1:11),m(1:11));

figure(2)
plot([bottom1 bottom]);hold on
plot([top1 top])
plot([mid1 mid])

However, the plot does not look smooth and at the origin, there's a sudden change which should not be there. How to correct it. enter image description here

Upvotes: 0

Views: 208

Answers (1)

anon
anon

Reputation:

Computing two separate integrals is not the right approach. The origin can be adjusted after you compute the integrals by shifting the x- and y-axis intercepts as needed.

i = 0:0.01e-06:1.3e-06;
t = rand(size(i));

top = cumtrapz(i,t);

plot(i-i(11), top-top(11))
xline(0)
yline(0)

enter image description here

Upvotes: 1

Related Questions