How to find the area between the x axis and positive section of a graph?
Show older comments
Hi
I'm trying to find the 2 separate areas for a Force * Displacement graph. The graph is basically 2 non-perfect, not-symmetrical half ellipses that connect at the x axis.
I need to specifically find the work done (area) for positive and negative forces but not sure how I could do it?
I have the data stored in 2 vectors but is there any way to only find the area of the graph above or below the x axis?
Or is my only choice to truncate the vectors to separate the graph into 2 and use 'trapz' function?
I am a beginner at MATLAB so please go easy on me!
Thank you for any help/tips :)
EDIT:
The reason I dislike the idea of removing the data to separate into positive and negative values of Y axis is because the data alternates and so becomes tiring having to remember which data values to remove from both vectors to maintain the correct plots.
I have found an easy way to separate the Y values from positive to negative (testing(testing < 0) = [];) but then I do not know which elements to delete in the X axis vector (as they can be both +ve and -ve).
If I do trapz(Y_Vector) when it has been separated into positive values, would it work to just multiply by the range of the X_Vector?
2 Comments
Image Analyst
on 15 Nov 2015
What are the 2 vectors you already have? Are they yPositive and yNegative, or are they y (both positive and negative in the same vector) and x?
Accepted Answer
More Answers (1)
Image Analyst
on 15 Nov 2015
Why don't you just sum the values above and below the axes
sumAbove = sum(Displacement1(Displacement1 >= 0));
sumBelow = -sum(Displacement1(Displacement1 < 0));
You can multiply by the deltaX spacing if you want calibrated units.
Categories
Find more on Numerical Integration and Differentiation 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!