主要就是照着一个例子写就是了
help ode45 或者ode23
源码:
function [T,Y]=solve_equation
% 向各位求助matlab求解微分方程组遇到的一个问题:
% 假设有以下的微分方程组
%
% u'(t)=-a*f1(t)*y(t);
% v'(t)=-b*v(t)+a*f1(t)*y(t);
% w'(t)=b*v(t);
% x'(t)=-a*f2(t)*v(t)+a*f1(t)*y(t)+a*f3(t)*y(t)+c*y(t);
% y'(t)= a*f2(t)*v(t) - a*f1(t)*y(t) - a*f3(t)*y(t) - c*y(t);
%
% 其中 f1(t)=0 if u(t)=0
% =1 if u(t)>0;
% f2(t)=0 if x(t)=0
% =1 if x(t)>0;
% f3(t)=0 if v(t)=0
% =1 if v(t)>0;
% a=1;b=0.1;c=0.5;
% 且u(0)=1000;v(0)=1;w(0)=0;x(0)=200;y(0)=0.
% 基本用法
% [T,Y] = solver(odefun,tspan,y0,options)
clear
clc
options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4 1e-4 1e-4 1e-5]);
[T,Y] = ode23(@myfun,[0 12],[1000,1,0,200,0],options);
function dy=myfun(t,y)
% 微分方程组
%
% 其中 f1(t)=0 if u(t)=0
% =1 if u(t)>0;
% f2(t)=0 if x(t)=0
% =1 if x(t)>0;
% f3(t)=0 if v(t)=0
% =1 if v(t)>0;
% a=1;b=0.1;c=0.5;
% 且u(0)=1000;v(0)=1;w(0)=0;x(0)=200;y(0)=0.
a=1;b=0.1;c=0.5;
dy=zeros(5,1);
% constraints
if y(1) == 0
f1 = 0;
elseif y(1) > 0
f1 = 1;
end
%2
if y(4) == 0
f2 = 0;
elseif y(4) > 0
f2 = 1;
end
%3
if y(2) == 0
f3 = 0;
elseif y(2) > 0
f3 = 1;
end
dy(1) = -a*f1*y(5);
dy(2) = -b*y(2)+a*f1*y(5);
dy(3) = b*y(2);
dy(4) = -a*f2*y(5)+a*f1*y(5)+a*f3*y(5)+c*y(5);
dy(5) = a*f2*y(2) - a*f1*y(5) - a*f3*y(5) - c*y(5);
在help里面的ode45查看例子,或者是在网上搜索关于matlab的ppt,照做就是的了哦
还有就是可以到matlab中文论坛去看看的哈