Finding the area between a graph and a line
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
x13dr.ck
am 2 Dez. 2015
Bearbeitet: Walter Roberson
am 4 Dez. 2015
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/152431/image.jpeg)
basically i need to find the distance (area) of the graph above the 1000mph mark on the graph (y axis).
i have tried using the trapz function however i can only seem to get the total area of the graph.
how would i go about this?
the x axis should read as hours, not seconds, so just ignore that. a quick response would be greatly appreciated.
so far the only code i have is:
for c=1:9
int=(trapz(Time_h,Velocity_milesph(:,c)));
disp(int)
end
what would i subtract from the trapz function to get just the area above 1000mph?
thanks
Akzeptierte Antwort
dpb
am 2 Dez. 2015
for c=1:9
ix=Velocity_milesph(:,c)>=1000;
int=(trapz(Time_h(ix),Velocity_milesph(:,c(ix))));
disp(int)
end
You'll still need to normalize by dt of course...
1 Kommentar
dpb
am 2 Dez. 2015
You may want to check on the granularity of the result of the check and improve the endpoints by interpolation to find the crossover if there's a fair disparity between the end values returned and the setpoint value.
Weitere Antworten (1)
Kirby Fears
am 2 Dez. 2015
The area below your curve and above Y=1000 is obtained by integrating (Velocity_milesph - 1000) over X values were Velocity_milesph is over 1000. The below code adjustments should be what you're looking for.
for c=1:9
interval = (Velocity_milesph(:,c)-1000) > 0;
fastArea = trapz(Time_h(interval),Velocity_milesph(interval,c)-1000);
disp(fastArea)
end
I'm not sure if trapz() is the right method for you since it uses unit spacing. Be sure that 1 unit of Time_h is considered very small relative to the amount of time that velocity is over 1000. Otherwise you will have large errors.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Numerical Integration and Differentiation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!