0

我正在尝试用空气阻力来模拟弹丸运动。

这是我的代码:

function [ time , x , y ] = shellflightsimulator(m,D,Ve,Cd,ElAng)

% input parameters are:
% m mass of shell, kg
% D caliber (diameter)
% Ve escape velocity (initial velocity of trajectory)
% Cd drag coefficient
% ElAng angle in RADIANS

A = pi.*(D./2).^2; % m^2, shells cross-sectional area (area of circle)
rho = 1.2 ; % kg/m^3, density of air at ground level
h0 = 6800; % meters, height at which density drops by factor of 2
g = 9.8; % m/s^2, gravity
dt = .1; % time step

% define initial conditions
x0 = 0; % m
y0 = 0; % m
vx0 = Ve.*cos(ElAng); % m/s
vy0 = Ve.*sin(ElAng); % m/s

N = 100; % iterations

% define data array
x = zeros(1,N + 1); % x-position,
x(1) = x0;
y = zeros(1,N + 1); % y-position,
y(1) = y0;
vx = zeros(1,N + 1); % x-velocity,
vx(1) = vx0;
vy = zeros(1,N + 1); % y-velocity,
vy(1) = vy0;


i = 1;
j = 1;

while i < N
    ax = -Cd*.5*rho*A*(vx(i)^2 + vy(i)^2)/m*cos(ElAng); % acceleration in x
    vx(i+1) = vx(i) + ax*dt; % Find new x velocity
    x(i+1) = x(i) + vx(i)*dt + .5*ax*dt^2; % Find new x position
    ay = -g - Cd*.5*rho*A*(vx(i)^2 + vy(i)^2)/m*sin(ElAng); % acceleration in y
    vy(i+1) = vy(i) + ay*dt; % Find new y velocity
    y(i+1) = y(i) + vy(i)*dt + .5*ay*dt^2; % Find new y position

    if y(i+1) < 0 % stops when projectile reaches the ground
        i = N;
        j = j+1;
    else
        i = i+1;
        j = j+1;
    end
end

plot(x,y,'r-')
end

这就是我放入 Matlab 的内容:

shellflightsimulator(94,.238,1600,.8,10*pi/180)

这会产生一个奇怪的情节,而不是抛物线。此外,这些位置似乎是负值。注意:ElAng 以弧度为单位!

我究竟做错了什么?谢谢!

4

1 回答 1

1

你的 vx 和 vy 不正确... vx= ve*sin(弧度角)和 vy 相反。你也不需要在你的初始速度和*之间加一个点...这仅用于逐个元素的乘法,并且初始速度是一个常数变量。但是,点乘数不会改变答案,只是没有必要..

于 2013-02-14T22:03:30.627 回答