简体   繁体   English

求解二次阻力的耦合微分方程

[英]Solving coupled differential equations of quadratic drag

Goal目标

I have been attempting to solve and plot the following coupled differential equation belonging to quadratic drag:我一直在尝试求解和绘制以下属于二次阻力的耦合微分方程:

在此处输入图片说明

The variables from the equations are defined as:方程中的变量定义为:

 c = 0.0004 m = 0.0027 starting position of projectile= (0,0.3) velocity on horizontal component = 2.05 velocity on vertical component = 0.55 g = 9.81

The problem问题

I cannot seem to solve the equation correctly and have some errors in programming我似乎无法正确解方程并且在编程中存在一些错误

What I have tried我试过的

I have tried using the code from online on MatLab and I have tried on Matematica but none of them is able to program this equation.我曾尝试在 MatLab 上使用在线代码,也曾在 Matematica 上尝试过,但他们都无法编写此等式。 I have also tried looking at SciPy on Python but it does not seem to work.我也试过在 Python 上查看 SciPy,但它似乎不起作用。

Could anybody please set me in the right direction on how to code this properly?任何人都可以请我在正确的方向上如何正确编码吗?

You can use a number of MATLAB built-in ODE solvers.您可以使用许多 MATLAB 内置 ODE 求解器。 ode45 is usually a good place to start. ode45通常是一个不错的起点。

You have two positions and two velocities (4 states total), so you need to pass 4 ODEs to the solver ode45 (one derivative for each state).您有两个位置和两个速度(总共 4 个状态),因此您需要将 4 个 ODE 传递给求解器ode45 (每个状态一个导数)。 If x(1) is the x-position, x(2) is the y-position, x(3) is the x-velocity, and x(4) is the y-velocity, then the derivative of x(1) is x(3) , the derivative of x(2) is x(4) and the derivatives of x(3) and x(4) are the ones given by your two drag equations.如果x(1)是 x 位置, x(2)是 y 位置, x(3)是 x 速度, x(4)是 y 速度,那么x(1)的导数是x(3)x(2)的导数是x(4)并且x(3)x(4)的导数是你的两个阻力方程给出的。

In the end, the MATLAB implementation might look like this:最后,MATLAB 实现可能如下所示:

c = 0.0004;
m = 0.0027;
p0 = [0; 0.3]; % starting positions 
v0 = [2.05; 0.55]; % starting velocities
g = -9.81; % gravitational acceleration

tspan = [0 5];
x0 = [p0; v0]; % initial states
[t_sol, x_sol] = ode45(@(t,x) drag_ode_fun(t,x,c,m,g), tspan, x0);

function dxdt = drag_ode_fun(t,x,c,m,g)
   dxdt = zeros(4,1);
   dxdt(1) = x(3);
   dxdt(2) = x(4);
   dxdt(3) = -c/m*x(3)*sqrt(x(3)^2+x(4)^2);
   dxdt(4) = g-c/m*x(4)*sqrt(x(3)^2+x(4)^2);
end

And you can plot the results as follows:您可以按如下方式绘制结果:

figure; 
subplot(3,1,1); grid on;
plot(x_sol(:,1), x_sol(:,2))
xlabel('x (m)'); ylabel('y (m)')

subplot(3,1,2); grid on;
plot(t_sol, x_sol(:,3))
xlabel('time'); ylabel('v_x (m/s)')

subplot(3,1,3); grid on;
plot(t_sol, x_sol(:,4))
xlabel('time')
ylabel('v_y (m/s)')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM