2017-12-16 9 views
0

이것은 발사체 모션 그래프입니다. 그래프를 그리기 전까지 전체 계산을 포함 시켰습니다. 계산 부분 다음에 코드를 사용하여 그래프의 설정을 변경하는 방법을 알지 못합니다. this is what i've plotted using this code below은 그래프의 그래프를 그래프에 완전히 포함 할 수 없습니다. 그래프의 절반 만 보여줍니다.

time = linspace(0, t, 1000); 
legends = {}; % Instantiate an empty cell for the angle legend. 
counter = 1; 
for A = 10: 10 : 90 
% Get the components of velocity in the x and y directions for this angle. 
vx = v*cosd(A); 
vy = v*sind(A); 
% Compute the distance along the x direction. x = x0 + x_velocity * time. 
xfinal = vx * time; 
% Compute the distance along the y direction. y = y0 + y_velocity_initial * 
%time + (1/2)*g*time^2 
yfinal = vy * time + (1/2) * 9.81 * time .^ 2; 
% Clip y to zero because we assume the projectile stays on the ground when 
%it hits. 
% It does not penetrate and have a negative y. 
yfinal(yfinal < 0) = 0; 
indexHitGround = find(yfinal > 0, 1, 'last'); 
fontSize=10 
plot(xfinal, yfinal, '-', 'LineWidth', 2); 
hold on; 
legends{end+1} = sprintf('Angle = %d', A); 
% Calculate the range in the x direction. 
xFinal(counter) = xfinal(indexHitGround); 
counter = counter + 1; 
end 
grid on; 
xlabel('X Coordinate', 'FontSize', fontSize); 
ylabel('Y Coordinate', 'FontSize', fontSize); 
title ('Projectile Trajectory', 'FontSize', fontSize) 
legend(legends); 
% Find the max xFinal and set the range of the graph to be that. 
xlim([0, max(xFinal)]); 
% Set up figure properties: 
% Enlarge figure to full screen. 
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0.2, 0.3, 0.8, 0.7]); 
% Get rid of tool bar and pulldown menus that are along top of figure. 
set(gcf, 'Toolbar', 'none', 'Menu', 'none'); 
% Give a name to the title bar. 
set(gcf, 'Name', 'Projectile Trajectory Demo Part 2', 'NumberTitle', 'Off') 

난 당신이 내 코드에서 오류를 지적하거나 나에게 줄 것인지 정말 감사하겠습니다 그래서 MATLAB에에 내가 초보자이야이 projectile trajectory

같은 것을 그릴려고 반면, 몇 가지 제안. 감사!

답변

1

문제는 데이터를 플로팅하는 방식이 아니라 궤적을 계산하는 데 사용되는 등식에 있습니다.

가속 구성 요소의 부호를 minus으로 변경해야합니다.

변경

yfinal = vy * time + (1/2) * 9.81 * time .^ 2; 

yfinal = vy * time - (1/2) * 9.81 * time .^ 2; 
코드에서

, tv

에 정의되지 않은 내가 코드를 테스트하기 위해 일부 값을 사용했습니다. 원하는 그래프의 화상에 대하여도

y0 아마도가
yfinal = y0+ vy * time - (1/2) * 9.81 * time .^ 2; 

는 궤적의 모양 y0=10 설정하기 식을 변경할 수도 정의되지 않은 (방정식에서 사용되지 않음)된다 : 이 도움이

enter image description here

희망,

Qapla '