我试图解决一个弹丸运动问题,在给定的初始条件下,确定起飞速度,这个问题被归结为一个由两个二阶微分方程组成的方程组。我的代码和问题在下面的图片中。问题方程中的常数的值被简化为常数a
、b
、c
和d
。
x¨(t)=-1/2m ρAC_d cos(arctan((y˙(t))/(x˙(t) )))(〖x˙(t)〗^2+ 〖y˙(t)〗^2)
y¨(t)=-1/2m(2mg+ρAC_d sin(arctan((y˙(t))/(x˙(t) )))(〖x˙(t)〗^2+ 〖y˙(t)〗^2)
# With the initial conditions:
x˙(0)=cosθ ∙ V_0
y˙(0)=sinθ ∙ V_0
x(0)=0
y(0)=0
我的解决方案代码如下所示;
syms x(t) y(t) a b c d u theta
% Equations
% d2x = -a*cos(arctan(dy/dx))*(((dx)^2)+(dy)^2));
% d2y = -b*(c + d*sin(arctan(dy/dx))*(((dx)^2)+(dy)^2));
%Constants
dx=diff(x,t);
dy=diff(y,t);
d2x=diff(x,t,2);
d2y=diff(y,t,2);
a=1;
b=2;
c=3;
d=4;
%Initial Conditions
cond1 = x(0) == 0;
cond2 = y(0) == 0;
cond3 = dx(0) == u*cos(theta);
cond4 = dy(0) == u*sin(theta);
conds = [cond1 cond2 cond3 cond4];
eq1 = -a*cos(atan(dy/dx))*(((dx)^2)+(dy)^2);
eq2 = -b*(c + d*sin(atan(dy/dx))*(((dx)^2)+(dy)^2));
vars = [x(t); y(t)];
V = odeToVectorField([eq1,eq2]);
M = matlabFunction(V,'vars', {'t','Y'});
interval = [0 5]; %time interval
ySol = ode23(M,interval,conds);
错误信息如下所示;
Error using mupadengine/feval (line 187)
System contains a nonlinear equation in 'diff(y(t), t)'. The system must be quasi-linear:
highest derivatives must enter the differential equations linearly.
Error in odeToVectorField>mupadOdeToVectorField (line 189)
T = feval(symengine,'symobj::odeToVectorField',sys,x,stringInput);
Error in odeToVectorField (line 138)
sol = mupadOdeToVectorField(varargin);
Error in velocity_takeoff (line 29)
V = odeToVectorField([eq1,eq2]);
为什么我会得到这些错误,我如何才能减轻这些错误?
发布于 2021-11-26 10:19:51
这看起来不太理想。没有必要使用三角函数,特别是在使用的形式中,它们可能会引入符号错误,请使用atan2
来避免这种情况。方程是一种简化形式。
as vectors dv/dt = -g*e_2 - k*speed*v, where speed = |v| is the norm of the vector
and additionally dxy/dt=v, xy=[x,y] being the position vector
在组件中实现,这给出了
function du_dt = motion(t,u)
x=u(1); y=u(2); vx=u(3); vy=u(4);
speed = hypot(vx,vy);
ax = -k*speed*vx;
ay = -k*speed*vy - g;
du_dt = [vx; vy; ax; ay];
end%function
This direct implementation is shorter and better readable than the way via symbolic equations.
You can adapt this for the different constants used, but any change in the constant structure is unphysical, or would need to be justified with some uncommon physical arguments.
https://stackoverflow.com/questions/70124207
复制