# 数学建模学习（29）：matlab求解微分方程组详细讲解，代码+案例讲解，学不会找我！

2021/8/21 6:31:58 浏览：

• 前言
• 求解微分方程组
• 求解矩阵微分方程组
• 总结

## 求解微分方程组

``````syms u(t) v(t)
``````

``````ode1 = diff(u) == 3*u + 4*v;
ode2 = diff(v) == -4*u + 3*v;
odes = [ode1; ode2]
``````

``````S = dsolve(odes)
``````

``````uSol(t) = S.u
vSol(t) = S.v
``````

``````[uSol(t), vSol(t)] = dsolve(odes)
``````

``````%案例一
syms u(t) v(t)
ode1 = diff(u) == 3*u + 4*v;
ode2 = diff(v) == -4*u + 3*v;
odes = [ode1; ode2]
[uSol(t), vSol(t)] = dsolve(odes)

``````

``````cond1 = u(0) == 0;
cond2 = v(0) == 1;
conds = [cond1; cond2];
[uSol(t), vSol(t)] = dsolve(odes,conds)
``````

``````%案例一
syms u(t) v(t)
ode1 = diff(u) == 3*u + 4*v;
ode2 = diff(v) == -4*u + 3*v;
odes = [ode1; ode2]
%[uSol(t), vSol(t)] = dsolve(odes)
cond1 = u(0) == 0;
cond2 = v(0) == 1;
conds = [cond1; cond2];
[uSol(t), vSol(t)] = dsolve(odes,conds)
``````

``````fplot(uSol)
hold on
fplot(vSol)
grid on
legend('uSol','vSol','Location','best')
``````

``````%案例一
syms u(t) v(t)
ode1 = diff(u) == 3*u + 4*v;
ode2 = diff(v) == -4*u + 3*v;
odes = [ode1; ode2]
%[uSol(t), vSol(t)] = dsolve(odes)
cond1 = u(0) == 0;
cond2 = v(0) == 1;
conds = [cond1; cond2];
[uSol(t), vSol(t)] = dsolve(odes,conds)
fplot(uSol)
hold on
fplot(vSol)
grid on
legend('uSol','vSol','Location','best')
``````

## 求解矩阵微分方程组

``````%矩阵微分
clear all
clc
syms x(t) y(t)
A = [1 2; -1 1];
B = [1; t];
Y = [x; y];
odes = diff(Y) == A*Y + B
``````

``````[xSol(t), ySol(t)] = dsolve(odes);
xSol(t) = simplify(xSol(t))
ySol(t) = simplify(ySol(t))
``````

``````C = Y(0) == [2; -1];
[xSol(t), ySol(t)] = dsolve(odes,C)
``````

``````clf
fplot(ySol)
hold on
fplot(xSol)
grid on
legend('ySol','xSol','Location','best')
``````

``````%矩阵微分
clear all
clc
syms x(t) y(t)
A = [1 2; -1 1];
B = [1; t];
Y = [x; y];
odes = diff(Y) == A*Y + B
[xSol(t), ySol(t)] = dsolve(odes);
xSol(t) = simplify(xSol(t))
ySol(t) = simplify(ySol(t))
C = Y(0) == [2; -1];
[xSol(t), ySol(t)] = dsolve(odes,C)
clf
fplot(ySol)
hold on
fplot(xSol)
grid on
legend('ySol','xSol','Location','best')

``````

## 总结

github下载地址：

``````https://github.com/89461561511656/matlab
``````