Find Indefinite Integral from Array Values
7 views (last 30 days)
Show older comments
I am trying to obtain indefinite integral of a function described by numerical values inside an array. To build such function i stardet trying to solve a simple integral of sin(x).
The problem i am facing is that i can't get the array containing the points representig the indefinite integral of the function (with constant of integration C=0). In other words vint_theor and vint_numeric must coincide.
John D'Errico on 31 Mar 2023
Sorry. there is no need for them to be exactly the same.
Cumtrapz is a simple variation of a fixed stepsize Euler integration, as if you were solving a simple first order ODE, using Euler's method. It is an APPROXIMATION. It is not the exact solution to an integral. Take more terms, the error may decrease. But even then, Euler's method need not always be a viable solution.
Having said that, WHY ARE YOU DOING WHAT YOU DID???????? Why did you subtract off the mean?
Your first error was here:
What is the step size? linspace genrates a vector of length N. How many intervals are there?
Therefore, what is the step size?
Next, what is the purpose of this next line?
vq is an APPROXIMATE estimate of the integral. Well, it would be if you had divided by N-1.
But then why subtract of the mean? What would the mean of that expression be?
vint_theor = 1 - cos(x); % The actual integral of sin(x), from 0 to x
vint_numeric = cumtrapz(v)*(b-a)/(N-1);
As you can see, the yellow and red curves now overlay on top of each other.
Find more on Array and Matrix Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!