用Matlab或计算求解耦合微分方程

时间:2013-01-04 11:24:43

标签: matlab differential-equations

通过Mat-lab或计算求解耦合非线性微分方程

equation 1:   x'(t) = -a* x(t) /(x(t) + y(t))
equation 2:   y'(t) = -b* y(t) /(x(t) + y(t))

我试过mathematica,但得到了一个非常复杂的解决方案。

Solve[{x'[t] == -a* x[t] /(x[t] + y[t]), y'[t] == -b* y[t] /(x[t] + y[t])}, {x, y}, t]

我如何绘制它?

我的初始条件是

 x(0) = xo
 y(0) = yo

此外,a和b是常数。

插入a和b的值后,我必须绘制x和y。 (a = 2,b = 5说)

2 个答案:

答案 0 :(得分:6)

在这种情况下需要注意很多事情:

  1. 您需要创建一个包含a和b的函数:

    function dy =soProblem(t,y,a,b)
        dy=[-a*y(1)/(y(1)+y(2)); -b*y(2)/(y(1)+y(2))];
    end
    
  2. 调用标准的ode函数:

    a = 2;
    b = 5; tend = 10; x0 = 1; y0 = 2;
    [T,Y] = ode45(@(t,y)soProblem(t,y,a,b),[0 tend],[x0 y0]);
    plot (T,Y)
    
  3. 意识到你可能手上有stiff equation

  4. 玩得开心识别理想的函数调用:

    [T15,Y15] = ode15s(@(t,y)soProblem(t,y,a,b),[0 tend],[x0 y0]);
    [T23t,Y23t] = ode23t(@(t,y)soProblem(t,y,a,b),[0 tend],[x0 y0]);
    [T23tb,Y23tb] = ode23tb(@(t,y)soProblem(t,y,a,b),[0 tend],[x0 y0]);
    %note ode23s doesn't converge (or at least takes forever)
    plot (T,Y,T15,Y15,T23t,Y23t,T23tb,Y23tb)
    
  5. 了解为什么mathematica变得焦躁不安

答案 1 :(得分:0)

在mathematica中:     试试ndsolve

在matlab中:

创建一个函数文件yourfunction.m:

function [Y_prime]=yourfunction(t, Y)
    Y_prime=[-2*Y(1)./(Y(1) + Y(2)) -5*Y(2)./(Y(1) + Y(2))];
end

然后

[T,Y] = ode45(yourfunction,[0 t_end],[x0 y0]);
plot(T,Y(:,1));
hold on
plot(T,Y(:,2));