my312318
2021-10-02 19:49
采纳率: 50%
浏览 43

Matlab解微分方程组

img

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • 技术专家团-Joel 2021-10-02 22:33
    最佳回答

    你好,答案仅供参考,一般符号求解和数值计算均可以这样做

    syms x1(t) x2(t) 
    syms a b real
    eq = [diff(x1)==a*x1+b*x2; diff(x2)==-b*x1+a*x2];
    conds = [x1(0)==1; x2(0)==1];
    [x1,x2] = dsolve(eq,conds);
    % (1) 四个解析解
    x1_sol1 = subs(x1, [a,b], [0.1,1])
    x2_sol1 = subs(x2, [a,b], [0.1,1])
    x1_sol2 = subs(x1, [a,b], [0.1,-1])
    x2_sol2 = subs(x2, [a,b], [0.1,-1])
    x1_sol3 = subs(x1, [a,b], [-0.1,1])
    x2_sol3 = subs(x2, [a,b], [-0.1,1])
    x1_sol4 = subs(x1, [a,b], [-0.1,-1])
    x2_sol4 = subs(x2, [a,b], [-0.1,-1])
    % (2)数值解:
    a_arr = [0.1, -0.1];
    b_arr = [1,-1];
    count = 0;
    figure(1);clf;
    for i = 1:1:numel(a_arr)
        for j = 1:1:numel(b_arr)
            a = a_arr(i); b = b_arr(j);
            count = count + 1;
            subplot(2,2, count)
            odefun = @(t,x) [a*x(1)+b*x(2); -b*x(1)+a*x(2)];
            [t,x] = ode45(odefun, [0, 10*pi], [1;1]);
            plot(x(:,1),x(:,2));%画相图
            title(['a=',num2str(a),',b=',num2str(b)])
        end
    end
    
    

    最后表达式

    x1_sol1 =
     
    exp(t/10)*cos(t) + exp(t/10)*sin(t)
     
     
    x2_sol1 =
     
    exp(t/10)*cos(t) - exp(t/10)*sin(t)
     
     
    x1_sol2 =
     
    exp(t/10)*cos(t) - exp(t/10)*sin(t)
     
     
    x2_sol2 =
     
    exp(t/10)*cos(t) + exp(t/10)*sin(t)
     
     
    x1_sol3 =
     
    exp(-t/10)*cos(t) + exp(-t/10)*sin(t)
     
     
    x2_sol3 =
     
    exp(-t/10)*cos(t) - exp(-t/10)*sin(t)
     
     
    x1_sol4 =
     
    exp(-t/10)*cos(t) - exp(-t/10)*sin(t)
     
     
    x2_sol4 =
     
    exp(-t/10)*cos(t) + exp(-t/10)*sin(t)
    
    

    相图

    img

    可知
    最终相图都是螺旋进入原点,且ab的正负决定了相图螺旋的方向

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题