New Users - Integrate Data

Ben Perston bperston at googlemail.com
Fri Dec 7 11:22:08 CST 2007


On 06/12/2007, Ciaran Mooney <general.mooney at googlemail.com> wrote:
>
>
> Is there a way of giving Octave a list of values (x, y) and then
> getting it to integrate those values? I have over 600 values so an
> even better way would be for octave to import a list of values from a
> file, and then perform the calculation.


To elaborate on Michael's response... put your data in a file in
comma-separated format (or something like it), so
1,2
3,4
etc

Then open Octave and load your data:
data = load('filename');
x=data(:,1); y=data(:,2);

And do the integration with trapz
integral=trapz(x,y)

trapz uses trapezoidal integration, i.e. it joins adjacent points with
lines, forming a bunch of trapezoids. There are a million other ways to do
it but this is probably the easiest.

If your x spacing is constant then you can just take the sum of all the y
values and multiply it by the difference between adjacent points in x. I
guess that's the rectangular approximation... a bit worse than the
trapezoid, but it may not matter depending on the accuracy you need. You can
do that calculation easily in a spreadsheet (but you should still start
using Octave anyway).

Ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www.cae.wisc.edu/pipermail/help-octave/attachments/20071207/bad12f0f/attachment-0001.html 


More information about the Help-octave mailing list