简体   繁体   中英

Solving coupled Differential Equation by Matlab or by calculations

Solving coupled non linear differential equation by Mat-lab or by calculations

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

I tried in mathematica but got a very comlicated solution.

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

How can I plot it?

My initial conditions are

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

Also, a and b are constants.

I have to plot x and y wrt t after inserting values of a and b . ( a= 2 , b =5 say )

A lot of things to note in this situation:

  1. You need to create a function that contains both a and 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. Call the standard ode function:

     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. Realize you may have a stiff equation on your hands.

  4. Have fun identifying the ideal function call:

     [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. Understand why mathematica becomes restless

In mathematica: Try ndsolve

In matlab:

Create a function file 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

and then

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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