Projectile Motion Equation with inputs of degree and first velocity
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want to write a Matlab code about projectile motion equation for my project but after a while I am stuck.
I cant plot the V_x,t diagram and I want to change V_z equation after V_z = 0, when z has its max value, but I couldnt do this. Can you help me?
And its also debugging.
clc
clear all
v0 = 262.22 ; %m/s
g= 9.801 ; %m/s^2
theta_0 = 85 ; %derece
v0_x = v0*cosd(theta_0) ; %m/s
v0_z = -v0*sind(theta_0) ; %m/s
t = 0:0.01:80 ;
for i = 0: length(t)
v_x = v0_x ;
x = v0_x.*t ;
v_z = g.*t + v0_z ;
v_z(1) = v0_z ;
z = 0.5*g.*t.^2 + v0_z.*t ;
theta = atand( -v_z / v_x ) ;
theta(1) = theta_0 ;
if v_z == 0
v_z = g.*t;
end
figure(1)
plot (t, theta) ;
figure(2)
plot (t, x) ;
figure(3)
plot (t, -z) ;
figure(4)
plot (t, -v_z) ;
figure(5)
plot(t,v0_x) ;
figure(6)
plot(x,-z) ;
end
3 commentaires
Réponses (1)
AndresVar
le 27 Fév 2022
Modifié(e) : AndresVar
le 27 Fév 2022
Here is an example
Note you don't have to loop for each time value because matlab can perform calculations on the vector
Note: i changed v0_z and t and z a little, but you can see how it works in general.
v0 = 262.22 ; %m/s
g = 9.801 ; %m/s^2
theta_0 = 85 ; %derece
x0 = 0;
z0 = 0;
v0_x = v0*cosd(theta_0) ; %m/s
v0_z = v0*sind(theta_0) ; %m/s
t = 0:0.1:60;
% velocity
v_x = v0_x*ones(size(t));
v_z = -g*t+v0_z;
% position
x = v0_x.*t+x0;
z = -0.5*g*t.^2+v0_z*t+z0;
figure;
tiledlayout(3,1)
nexttile;
plot(x,z)
xlabel('x'),ylabel('z');
nexttile;
plot(t,v_x);
xlabel('t'),ylabel('v_x');
nexttile;
plot(t,v_z);
xlabel('t'),ylabel('v_z');
% to change v_z at maximum height
% for example here i set it to constant 2 m/s
% then the location also changes z=2*t+z0...
[~,peakIdx]=min(abs(v_z));
t2 = t(peakIdx:end)-t(peakIdx);
v_z(peakIdx:end)=2;
z(peakIdx:end)=2*t2+z(peakIdx);
figure
tiledlayout(1,2)
nexttile;
plot(t,v_z)
xlabel('t');ylabel('v_z');
nexttile;
plot(x,z);
xlabel('x');ylabel('z');
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!