The data statistics in MATLAB plot does not show the correct value

Intro to engineering MATLAB courseware course.
I have a plot of a projectile, where y-axis is the height of the projectile, and x-axis is the time.
When I view the 'Data Statistics' in the drop down tools on the plot, it shows me the correct maximum value for y, but for the maximum value of x it just shows 20 for all the plots. 20 is the maximum the axis goes, but I need the time it took for the projectile to hit the ground, so the maximum x value for each plot. As you can see in the plot below for theta = 10, x should be less than 5 but it shows 20.
The code is:
% initial speed in m/s
V0 = 90;
% angle in degrees
theta = [10,25,45,65,85]';
% initial height above the ground in meters
y0 = 0;
% time in seconds
t = 0:0.01:20;
% gravity in m/s^2
g = 9.81;
% x position of the projectile in meters
xposition = (V0.*cosd(theta)).*t;
% y position of the projectile in meters
yposition = (-0.5*g.*(t.^2))+((V0.*sind(theta)).*t)+y0;
%% plotting the yposition of the projectile vs the time
plot(t , yposition)
xlabel('Time (s)')
ylabel('Projectile Height (m)')
ylim([0 500])
legend('Theta = 10', 'Theta = 25', 'Theta = 45', 'Theta = 65', 'Theta = 85')
Please could you help.

8 Kommentare

What is the data for X and Y? We cannot judge what the correct statistics are without the original data.
Adam Danz
Adam Danz am 10 Okt. 2022
Bearbeitet: Adam Danz am 10 Okt. 2022
My naive guess is that each of those lines continue to x=20 either at y=0 or below y=0 in which case, the max x value of 20 is correct. If this is the case, you can find the index value idx where the blue curve reaches y<=0, ignoring the initial coniditions, and then use that index value to get the time x(idx).
can you share the code?
"My naive guess is that each of those lines continue to x=20 either at y=0 or below y=0 ..."
Nothing naive about it at all, Adam, the image above shows the min y for theta=10 is -1649.
OP forgot to stop the simulation for each angle at the time the projectile returned to earth and log the time that occurred. Or, as you note, he/she can now search/interpolate for the crossing point after the fact.
I have added my code to the question.
Could you please tell me how to stop this simulation when the projectile hits the ground, and the other method of indexing. I know how to use the min and max function when indexing but how do I get the index of the x value when y = 0. It will be two values because y = 0 at the x = 0, and y = 0 at x = 'projectile hits the ground'.
Once the ball hits the ground, it's y value should remain at y=0 for the remainder of the time (assuming no bounce). So you'll see flat lines at y=0 after the curves reach the ground.
That's an easy change.
Hint:
max(yposition,0)
Could you please tell me how to stop this simulation when the projectile hits the ground
Solve the equation
(-0.5*g.*(t.^2))+((V0.*sind(theta)).*t)+y0 = 0
for the nontrivial value of t (quadratic equation, should be no problem).

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 10 Okt. 2022

Bearbeitet:

am 11 Okt. 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by