在MATLAB中求解4个耦合微分方程

时间:2016-12-19 10:50:18

标签: matlab

我有一组耦合的ODE,我希望用MATLAB解决。方程式如下。

Coupled differential equations

我有4个边界条件:x(0),y(0),v(0),theta(0)。如果我尝试使用dsolve解决此问题,我会收到警告,指出无法找到明确的解决方案。 这是我使用的代码。

syms x(t) y(t) v(t) theta(t)

% params
m = 80;             %kg
g = 9.81;           %m/s^2
c = 0.72;           %
s = 0.5;            %m^2
theta0 = pi/8;      %rad
y0 = 0;             %m
rho = 0.94;         %kg/m^3


% component velocities
xd = diff(x,t) == v*cos(theta);
yd = diff(y,t) == v*sin(theta);

% Drag component
D = c*rho*s/2*(xd^2+yd^2);

% Acceleration
vd = diff(v,t) == -D/m-g*sin(theta);

% Angular velocity
thetad = diff(theta,t) == -g/v*cos(theta);

cond = [v(0) == 10,y(0) == 0, x(0) == 0, theta(0) == theta0];
dsolve([xd yd vd thetad],cond)

1 个答案:

答案 0 :(得分:2)

这看起来有点像某种钟摆......

你的等式有

这个词
dθ(t)/dt = C·cos(θ(t)) 

类似于钟摆的ODE,至少它有同样的问题:这个方程的闭合形式解是未知的。我相信它甚至被证明不存在,但我并非百分之百确定。

无论如何,数字上它是一块蛋糕。以下是ode45

的示例
function my_ode()

    % parameters
    m   = 80;     % kg
    g   = 9.81;   % m/s² 
    c   = 0.72;   % -
    s   = 0.5;    % m²
    rho = 0.94;   % kg/m³ 

    theta0 = pi/8; % rad
    v0     = 10;   % m/s
    x0     = 0;    % m
    y0     = 0;    % m

    tspan = [0 10]; % s


    % function to compute derivative of
    % Z = [x, y, th, v]
    function dZdt = odefcn(~,Z)

        % rename for clarity (NOTE: x and y are not used)
        th = Z(3);   cth = cos(th);
        v  = Z(4);   sth = sin(th);

        % Compute derivatives
        dxdt  = v * cth;
        dydt  = v * sth;
        dthdt = -g/v * cth;        
        dvdt  = -c*rho*s*v^2/(2*m) - g*sth;

        % assign to ouptut respecting either row or columnvector inputs
        dZdt = Z;
        dZdt(:) = [dxdt dydt dthdt dvdt];        

    end

    % Integrate the ODE
    Z0 = [x0 y0 theta0 v0];    
    [t,Z] = ode45(@odefcn, tspan, Z0);



    % Example outputs
    x  = Z(:,1);   th = Z(:,3);
    y  = Z(:,2);   v  = Z(:,4);

    F = figure; hold on
    P = get(F, 'position');    
    set(F, 'position', [P(1:2) 3*P(3) P(4)]);    

    subplot(1,3,1)
    plot(x,y, 'b'), grid on
    xlabel('x [m]'), ylabel('y [m]')

    subplot(1,3,2)
    plot(t,v, 'b'), grid on
    xlabel('t'), ylabel('v [m/s]')

    subplot(1,3,3)
    plot(t,th, 'b'), grid on
    xlabel('t'), ylabel('\theta [rad]')

end

请注意,与精确解决方案不同,您必须指定开始和结束时间(在变量tspan中捕获)。另请注意,我已使用标识cos²θ + sin²θ = 1来简化D

示例输出:

enter image description here