first_integral_plot = cumtrapz(x, f);
second_integral_plot = cumtrapz(x, first_integral_plot );
Why do you think this has not worked? The first integral is of a linear kernel. So we should see quadratic behavior in the output.
That looks nicely quadratic to me. Now, the integral of a quadratic would seem to be cubic in nature.
I'l bite. What seems wrong to you?
Let me guess. You forget that an integral actually has an undetermined constant in there. So the indefinite integral of 6*x should be 3*x^2 + C. Of course, cumtrapz, being a purely numerical code, does not understand what to do with that undetermined constant. So it sort of ignores it. This is NOT the same thing as to asume the constant was zero. In fact, the implicit presumption of cumtrapz is that at the first point, the integral was ZERO. And that is correct, because cumtrapz is a DEFINITE integration tool. That is, what is the integral of F from -100 to some point X? When X is -100, that value is ZERO.
So what is cumtrapz producing? I'll do the same computation in a symbolic form, and then plot what we get.
Again, that is a DEFINITE INTEGRAL. Does it look like what cumtrapz produced?
Now, when you integrate that a second time, we see:
Fint2 = expand(int(Fint,x,-100,x))
It should not be surpriise that the two agree remarkably well. And of course, we can check the result:
All seems to be happy.
Never forget those constants of integration. Sometimes they come back and bite you.