2013-01-04 56 views
0

求解耦合非線性微分方程通過Matlab或通過計算問題的求解微分方程通過Matlab或通過計算

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

我試圖在mathematica但得到了一個非常comlicated溶液。

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 wrt t。 (A = 2,B = 5說)

回答

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)); 
4

在這種情況下要注意很多事情:

  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. 調用標準頌歌功能:

    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. 明白爲什麼數學變得焦躁不安