如果是常微分方程,可以用dsolve函数。该函数可以解单变量常微分方程或者多变量常微分方程组,所以5个变量也不在话下。
调用格式如下:
[y1,...,yN] = dsolve(eqns) solves the system of ordinary differential equations eqns and assigns the solutions to the variables y1,...,yN.
如果有初始条件,可以把条件一起传给函数来定解:
[y1,...,yN] = dsolve(eqns,conds) solves the system of ordinary differential equations eqns with the initial or boundary conditions conds.
给出一个2个变量的微分方程组求解代码:
syms x(t) y(t)
z = dsolve(diff(x) == y, diff(y) == -x,x(0)==1,y(0)==1);
x=z.x,y=z.y
运行结果为:
x =
cos(t) + sin(t)
y =
cos(t) - sin(t)