I am looking for numerical integration with matlab. I know that there is a trapz function in matlab but the precision is not good enough. By searching it online, I found there is a quad function there it seems only accept symbolic expression as input. My data is all discrete and one-dimensional. Is that any way to use quad on my data? Thanks.
相关问题
- Extract matrix elements using a vector of column i
- Spring Integration - Inbound file endpoint. How to
- How can I set the SVN password with Emacs 23.1 bui
- How do you get R's null and residual deviance
- Global overloading of == and != for floating-point
相关文章
- How do I append metadata to an image in Matlab?
- How can I write-protect the Matlab language?
- `std::sin` is wrong in the last bit
- Escape sequence to display apostrophe in MATLAB
- Vertical line fit using polyfit
- Reading .mat file using C: how to read cell-struct
- Is it possible to compare 3D images?
- How can I find row to all rows distance matrix bet
Integration of a function of one variable is the computation of the area under the curve of the graph of the function. For this answer I'll leave aside the nasty functions and the corner cases and all the twists and turns that trip up writers of numerical integration routines, most of which are probably not relevant here.
Simpson's rule is an approach to the numerical integration of a function for which you have a code to evaluate the function at points within its domain. That's irrelevant here.
Let's suppose that your data represents a time series of values collected at regular intervals. Then you can plot your data as a histogram with bars of equal width. The integrand you seek is the sum of the areas of the bars in the histogram between the limits you are interested in.
You should be able to apply this approach to data sets where the x-axis (ie the width of the bars in the histogram) does not show time, to the situation where the bars are not of equal width, to the situation where the data crosses the x-axis, and most reasonable data sets, quite easily.
The discretisation of your data establishes a limit to the accuracy of the result you can get. If, for example, your time series is sampled at 1sec intervals you can't integrate over an interval which is not a whole number of seconds by this approach. But then, you don't really have the data on which to compute a figure with any more accuracy by any approach. Sure, you can use Matlab (or anything else) to generate extra digits of precision but they don't carry any meaning.
An answer to your question would be no. The only way to perform numerical integration for data with no expression in Matlab is by using the
trapz
function. If it's not accurate enough for you, try writing your own quad function as Li-aung said, it's very simple, this may help.Another method you may try is to use the powerful Curve Fitting Tool
cftool
to make a fit then use theintegrate
function which can operate oncfit
objects (it has a weird convention, the upper limit is the first argument!). I don't think you will get much accurate answers thantrapz
, it depends on the fit.Use the spline function in MATLAB to interpolate your data, then integrate this data. This is the standard method for integrating data in discrete form.
You can use
quadl()
to integrate your data if you first create a function in which you interpolate them.And then feed it to the
quadl()
function: