"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <ig2ojd$r6$1@fred.mathworks.com>...
> "George " <mrhotpotato@hotmail.co.uk> wrote in message <ig2lnh$lgp$1@fred.mathworks.com>...
> > Recently I undertook the testing a a spring damper system. The tests involved cycling the unit with a sinusoidal displacement and recording the force.
> >
> > From these tests plots are created which look like this: http://www.flickr.com/photos/57922959@N02/5328255652/
> >
> > I need to find the area enclosed by the data, can Matlab do this?
> > I have tried to use the polyarea command to no success (areas that I know to be larger than others come out smaller)
> >
> > Thanks
> > George.
>
> help trapz
> You'll have to call it twice: integrate the top part, subtract the integral of the bottom part. The index that corresponds to the point between the two parts is:
> [trash, idx] = max(x_values);
> so
> the_area = trapz(x(1:idx),y(1:idx))trapz(x((idx+1):end),y((idx+1):end)
>
> Good Luck!
I realize this thread is old but I am performing a similar task as the OP and wanted to check my hand calcs from a printout to the trapz method in matlab. I was getting a drastically different answer than my hand calcs so I ran a trapz on each individual output
upper_area = trapz(x(1:idx),y(1:idx)) = positive value
lower_area = trapz(x((idx+1):end),y((idx+1):end)) = negative value
I discovered that the trapz output for the bottom part of the curve generated a negative value. I think it has to do with the fact that the displacement is decreasing as the array index goes up. I changed the equation to add the two together and I got within 1.1Nmm of my hand calc.
Just an FYI for anyone else that reads this in the future.
the_area = trapz(x(1:idx),y(1:idx))+trapz(x((idx+1):end),y((idx+1):end)
