2017-12-16 6 views
0

これは射影モーショングラフです。グラフのプロットまで完全な計算が含まれています。私は計算部分の後にコードを使ってグラフの設定を変更する方法を理解していません。 this is what i've plotted using this code belowは完全にグラフのグラフをmatlab guiに含めることはできません。プロットの半分だけを表示します

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') 

私はこの projectile trajectory

のようなものをプロットしようとしているのに対し、私はあなたが私のコードでエラーを指摘したり、私を与える場合ので、私は本当に感謝してMATLABに初心者ですいくつかの提案。ありがとう!

答えて

1

問題は、データをプロットする方法ではなく、軌跡を計算するのに使用される式に問題があります。

アクセラレーションコンポーネントの符号をminusに変更する必要があります。

変更

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

yfinal = vy * time - (1/2) * 9.81 * time .^ 2; 
あなたのコードで

tv

に、定義されていない私は、コードをテストするためにいくつかの値を使用しました。

また、所望のグラフの画像に関して、y0が定義されていない(と式で使用されていない)、おそらくあなたは軌道がどのように見えるy0=10を設定

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

に式を変更する場合があります:このことができます

enter image description here

希望、

Qapla」

関連する問題