• [y1, …, yN ] = dsolve(eqns, conds ) eqns:微分方程(组),conds 为初值条件或边界条件

    求解微分方程的通解

    例1

  • 求解常微分方程matlab求微分方程的解析解 - 图1

    1. syms y(x)%定义符号变量
    2. dsolve(x^2+y+(x-2*y)*diff(y)==0)

    求解常微分方程的初边值问题

    例2

    matlab求微分方程的解析解 - 图2 ```matlab syms y(x) dy=diff(y); d2y=diff(y,2); y=dsolve(diff(y,3)-diff(y,2)==x,y(1)==8,dy(1)==7,d2y(2)==4); y=simplify(y)

y =

(17x)/2 + 7exp(x - 2) - 7xexp(-1) - x^2/2 - x^3/6 + 1/6

  1. <a name="FtjbW"></a>
  2. # 求解常微分方程组
  3. <a name="uVhLL"></a>
  4. ## 例3
  5. ![](https://cdn.nlark.com/yuque/__latex/e3f67e80cd1e91122658fd67e1b92928.svg#card=math&code=%5Cbegin%7Bcases%7D%0Af%5E%7B%27%27%7D%2B3g%3Dsinx%5C%5C%0Ag%5E%7B%27%7D%2Bf%5E%7B%27%7D%3Dcosx%0A%5Cend%7Bcases%7D%0A%5Cquad%0Af%5E%7B%27%7D%282%29%3D0%2Cf%283%29%3D3%2Cg%285%29%3D1&id=YvFK3)
  6. ```matlab
  7. syms f(x) g(x)
  8. df=diff(f);
  9. [f1,g1]=dsolve(diff(f,2)+3*g==sin(x),diff(g)+df==cos(x))
  10. f1=simplify(f1);
  11. g1=simplify(g1);
  12. [f2,g2]=dsolve(diff(f,2)+3*g==sin(x),diff(g)+df==cos(x),df(2)==0,f(3)==3,g(5)==1)
  13. f2=simplify(f2);
  14. g2=simplify(g2);

求解线性常微分方程组

一阶齐次线性微分方程组

matlab求微分方程的解析解 - 图3

例4

  • 求解初值问题

matlab求微分方程的解析解 - 图4

  1. syms x1(t) x2(t) x3(t)
  2. X=[x1;x2;x3];
  3. A=[2 1 3;0 2 -1;0 0 2];
  4. B=[1;2;1];
  5. [x1,x2,x3]=dsolve(diff(X)==A*X,X(0)==B)

非齐次线性方程组

matlab求微分方程的解析解 - 图5

例5

  • 求解初值问题

matlab求微分方程的解析解 - 图6

  1. syms x1(t) x2(t) x3(t)
  2. X=[x1;x2;x3];
  3. A=[1 0 0;2 1 -2;3 2 1];
  4. B=[0;0;exp(t)*cos(2*t)];
  5. X0=[0;1;1];
  6. %[x1,x2,x3]=dsolve(diff(X)==A*X+B,X(0)==X0)
  7. X=dsolve(diff(X)==A*X+B,X(0)==X0)
  8. X=simplify([X.x1;X.x2;X.x3])%化简
  9. pretty(X)%数学显示
  10. >>> X =
  11. 0
  12. -(exp(t)*(2*sin(2*t) - 2*cos(2*t) + t*sin(2*t)))/2
  13. (exp(t)*(4*cos(2*t) + 5*sin(2*t) + 2*t*cos(2*t)))/4
  14. / 0 \
  15. | |
  16. | exp(t) (sin(2 t) 2 - cos(2 t) 2 + t sin(2 t)) |
  17. | - --------------------------------------------- |
  18. | 2 |
  19. | |
  20. | exp(t) (cos(2 t) 4 + sin(2 t) 5 + t cos(2 t) 2) |
  21. | ----------------------------------------------- |
  22. \ 4 /