弹力运动与拖曳力Matlab

时间:2012-11-28 01:42:01

标签: matlab drag octave motion projectile

我正试图用空气阻力模拟弹丸运动。

这是我的代码:

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是弧度!

我做错了什么?谢谢!

1 个答案:

答案 0 :(得分:1)

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