Matlab脚本在数值上解决弹丸运动的问题

时间:2015-02-01 21:55:25

标签: matlab modeling projectile

目前我有一个编写Matlab脚本的任务,以数字方式解决从各种角度发射的炮弹问题,无论是否有空气摩擦。当然,我正在考虑如何解决空气摩擦组件,但首先我需要创建没有空气摩擦的模型,我无法弄清楚它的生命是如何分解的。这是我的代码:

clc;
clear all;
close all;

% Setting initial conditions such as angle, number of sampling intervals,
% initial x- and y-positions, etc.
N_points=10000;
total_time=200;
angle_initial=20;
gravity_initial=9.81;
velocity_initial=700;
y_initial=0;
x_initial=0;

% Set time vector, x-position and y-position vectors, their initial values,
% and sampling interval.

delta_t=total_time/N_points;
y=zeros(N_points,1);
x=zeros(N_points,1);
time=zeros(N_points,1);
y(1)=y_initial;
x(1)=x_initial;

%Begin loop to actually calculate y-position through time.
%

for step=1:N_points-1
    time(step+1)=time(step)+delta_t;
    y(step+1)=y(step)+((-gravity_initial*sind(angle_initial)*time(step+1)+velocity_initial*sind(angle_initial))*delta_t);
end

% Find all values of y-position vector less than zero and eliminate them
% from vector, thus giving us only points before the projectile 'hits' the
% ground.

a_1=find(y<0);
r_1=[a_1];
y(r_1)=[];
b_1=length(y)

%Create x-position vector starting from zero to maximum possible range of
%projectile, separated into equal intervals corresponding to number of
%positive elements in the y-position vector. This way, the x- and y-vectors
%will match when they are plotted together.
x=linspace(0,((velocity_initial^(2))/gravity_initial)*sind(2*angle_initial),b_1);

%plot x- and y-position vectors.
plot(x,y,'r')

我无法弄清楚为什么这个功能正在'炸毁';当这个代码运行时,射弹的射程是正确的,但高度不是。我真的看不出我在哪里错了;我在网上看了很多例子和其他东西,无论我尝试什么样的变化,它们都表现出太高的轨迹高度。任何人都可以提供我在哪里出错的线索吗?

0 个答案:

没有答案