MATLAB: Integrating non-syms var

arrayintegratenon-symsvar

I have:
x=0:1/8000:0.03;
y=sin(x);
How do I integrate y? Essentially I need an array of values which are the values of -cos(x). I can't use symsvar because I am trying to graph y on the same plot which currently graphs an array.
Thanks in advance

Best Answer

trapz(x, y)
"I can't use symsvar because I am trying to graph y on the same plot which currently graphs an array."
That does not actually matter; you can use "hold on" before using fplot() or ezplot() .
Besides, the integral of y is going to be a single value, which you are probably not going to plot.
Perhaps you were thinking of cumulative integral, which can be plotted. For that use cumtrapz(x,y)
Related Question