Hans
Hans

Reputation: 383

How to get the integral (function) from a vector?

I have a vector than can be plotted and I would like to compute its integral. I don't mean the total area below, but how it evolves over the domain of integration. Basically, its "indefinite" integral. Is this possible? maybe via interpolation? Since I am working with Chebyshev differentiation matrices, do you know if there is an equivalent for integration?

Thank you

Upvotes: 1

Views: 179

Answers (1)

Luis Mendo
Luis Mendo

Reputation: 112659

You probably want cumtrapz:

x = linspace(0,2*pi,1000); % example x axis values
y = sin(x); % example function
I = cumtrapz(x, y); % compute its integral
plot(x, y, x, I) % plot them
grid on % grid

enter image description here

Upvotes: 1

Related Questions