我正在尝试计算下方角度θ的射弹的最大距离和最大高度。
我假设我绘制距离θ和高度相对于θ(在同一图表上)的图形的方法是错误的。关于它的任何指示都会有所帮助。
e=100;
m = 1;
g = 9.8;
cd = 0.55;
r = 0.02;
p = 1.21;
a = pi*r^2;
v = sqrt((2*e)/m);
k = (1/2)*cd*a*p;
% For loop to calculate Distance and
for theta = (0:pi/4);
vx = v*cos(theta);
vy = v*sin(theta);
t = sqrt(m/(g*k))*atan(vy*sqrt(k/(m*g)));
x = (m/k)* log((1/vx)+(k/m)*t) - log(1/(vx));
h = (m/k)*(log(cos(atan(vy*sqrt(k/(m*g))-sqrt((g*k)/m)*t))-log(cos((atan(vy*sqrt(k/m*g)))))));
plot (x, theta);
plot (h, theta);
end
答案 0 :(得分:1)
您不需要遍历不同的theta值。试试这个:
theta = (0:0.01:pi/4); % theta = [0 0.01 0.02 0.03 ... pi/4]
vx = v*cos(theta);
vy = v*sin(theta);
t = sqrt(m/(g*k)) * atan(vy .* sqrt(k/(m*g))); % element wise matrix multiplication
x = (m/k)* log((1./vx)+(k/m)*t) - log(1./(vx));
h = (m/k)*(log(cos(atan(vy .* sqrt(k/(m*g))- sqrt((g*k)/m)*t))-log(cos((atan(vy .* sqrt(k/m*g)))))));
plot (x, theta);
plot (h, theta);
x vs theta:
也试试这个:
MATLAB: Creating a Function to Plot Projectile with Drag
MATLAB: Numerical approximation of projectile motion with air resistance
希望这有帮助!
答案 1 :(得分:0)
未定义变量t
。循环变量也应该是整数,例如:
N = 10;
for i = 0:N-1
theta = pi/4*i/(N-1)
(...)
end