[MATLAB] numerical calculation of differential equation sets
We use the ode45 function When we cannot use dsolve to do symbolic solving.
The function prototype is
[T,y] = Ode45 (odefun,tspan,y0) Example
[t,y] = Ode45 (odefun,tspan,y0,options) Example
[T,y,te,ye,ie] = Ode45 ( odefun,tspan,y0,options)
sol = ode45 (___)
Write the function file first. m as the first parameter of the Ode45 Odefun
Function y = Fun (t,x,flag,k)
%flag are a [] to mark the args
%---------------
%some global setting
lamda=1 ;
%---------------
y=[x (2) *k,lamda*x (2) * (1-x (1)-X (2))-k*x (2)] ';
End
T is the default argument, and X is a vector of dependent variables. The return value is the first derivative of the corresponding dependent variable vector, or we can write
Function y = Fun (t,x,flag,k)
%flag are a [] to mark the args
%---------------
%some global setting
LAMD a=1;
%---------------
Y=zero (2,1)
y (1) =x (2) *k;
Y (2) =lamda*x (2) * (1-x (1)-X (2))-k*x (2);
End
Then write Ode45
[T,x]=ode45 (' fun ', tspan,[0,x0],[],each);
Tspan for [0:10] argument range
The third parameter is the initial value vector
The fourth parameter empty array is used as flag to distinguish the parameters of the incoming fun and the parameters required for Ode45