フィルターのクリア

Projectile Motion Graph, Loop to prevent it going below zero

1 回表示 (過去 30 日間)
Mitul Dattani
Mitul Dattani 2017 年 4 月 3 日
回答済み: Vidip 2024 年 5 月 15 日
Hi, ive got this set of code in which it shows the height vs time of a projectile 10m above the ground fired at a specific angle, however the height goes below zero and im not too sure how to loop it
Just before the plot (x,y) i tried adding in while y >= 10 then and end statement after the plot (x,y) thinking it would work but to no avail.
%======================================================================%
%Arrow is fired from a cliff plot its projectile motion 10m above ground
%======================================================================%
clear all %clears workspace
angle = 0.4; %Size of angle it is fired at in radians from cliff
V0 = 20; %inital velocity = 20 m/s
g = -9.81; %Gravity force taking up as +ive
t = 0:0.1:3; %time
h = 10; %height
%Ax = 0; %Vertical Acceleration
Ay = g; %Horizontal Acceleration
%======================================================================%
%xVelocity = V0 * cos(angle);
yVelocity = V0 * sin(angle); %Vertical Velocity
x = t; %x axis = time
y = h + (yVelocity * t + (1/2) * Ay * t.^2); %s = ut + (0.5)at^2
%======================================================================%
plot(x, y);%+10 BECAUSE 10M ABOVE GROUND
%%%%ADD IN LOOP TO STOP WHEN Y AXIS GOES BELOW ZERO THEN INCREASE
%%%%INCREMENTS
%======================================================================%
caption = sprintf('Angle = %.2f radians', angle); %Title of graph defined
title(caption, 'FontSize', 15); %Title of graph inserted
grid on; %Grid on graph
%======================================================================%
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
%======================================================================%
end

回答 (1 件)

Vidip
Vidip 2024 年 5 月 15 日
In the context of adjusting your MATLAB plot for a projectile motion scenario to ensure the plot dynamically stops at the point where the projectile descends below 10 meters, you can utilize the ‘xlim’ function effectively. First, identify the index where the height (y) first drops below 10 meters by using ‘find(y < 10, 1)’. If such an index is found, you can use it to determine the corresponding time (t) at which this occurs. Then, apply ‘xlim([0, t(index)])’ to set the x-axis limits from the start of the motion to this critical time, ensuring the plot visually represents the projectile's trajectory only while it's above the specified 10-meter threshold.
For more information, you can refer to the documentation link below –

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by