This is not a question about MATLAB, just understanding some basic mathematics. At least, understanding calc 101.
First, you need ot understand that a trapezoidal rule is NOT an exact integration, any more than differentiation of a numerical series using diff is an exact differentiation. (Worse, if you are not careful about how you did the differentiation, you may have gotten that part wrong too, because diff, as applied to a sequence is NOT a derivative, but a simple difference between consecutive terms. You can make it an approximate derivative, by dividing by the stride between terms. But that is only an approximation.) Note that the gradient function will give you a better approximation for the derivative, as well as properly taking care of the stride between points in the series.
Next, when you integrate a function, you should have learned that the result actually has a constant of integration. (I did say basic calc.) But if you just forget about that constant of integration, then you are impllicitly assuming it is zero, and that is often the wrong thing to do. Did you ignore the constant of integrtion? I think you did, as it will be crucially important! In fact, there are two such constants of integration to worry about.
If you want a better answer, then you should show what you did, as this clearly looks like homework. It is far better for someone to correct what you would try than to write your homework for you.