代码之家  ›  专栏  ›  技术社区  ›  Fifmut

Scilab绘图显示不正确的ode值

  •  0
  • Fifmut  · 技术社区  · 8 年前

    我试图在scilab中创建异步电机的模型,并显示转速、电流和扭矩随时间变化的图形。它看起来很长,但你不需要全部阅读。

    fHz = 50;   
    Um = 230;
    p = 3;
    we = 2*%pi*fHz/p; 
    wb = 2*%pi*50; 
    Rs = 0.435; 
    Rr = 0.64; 
    Ls = 0.0477;
    Xls = wb*Ls; // [Ohm] 
    Lr = 0.0577;
    Xlr = wb*Lr; // [Ohm]
    Lm = 0.012;
    Xm = wb*Lm; // [Ohm]
    Xml = 1/(1/Xls + 1/Xm + 1/Xlr) // [Ohm];
    D = 0.0002;
    J = 0.28;
    Mt = 0.0;
    
    function [xdot]=AszinkronGep(t, x, Um, fHz)
    
    xdot = zeros(12, 1);
    
    Fsq = x(1);
    Fsd = x(2);
    Frq = x(3);
    Frd = x(4);
    wr = x(5);
    isabc(1) = x(6);
    isabc(2) = x(7);
    isabc(3) = x(8);
    irabc(1) = x(9);
    irabc(2) = x(10);
    irabc(3) = x(11); 
    
    Ua = Um*sin(2*%pi*fHz*t);
    Ub = Um*sin(2*%pi*fHz*t - 2*%pi/3);
    Uc = Um*sin(2*%pi*fHz*t + 2*%pi/3);
    
    Uab = 2/3*[1, -0.5, -0.5; 0, sqrt(3)/2, -sqrt(3)/2]*[Ua;Ub;Uc];
    
    phi = 2*%pi*fHz*t;
    Udq = [cos(phi), sin(phi); -sin(phi), cos(phi)]*Uab;
    Usd = Udq(1);
    Usq = Udq(2);
    Urd = 0;
    Urq = 0;
    
    isd = ( Fsd-Xml*(Fsd/Xls + Frd/Xlr) )/Xls;
    isq = ( Fsq-Xml*(Fsq/Xls + Frq/Xlr) )/Xls;
    ird = ( Frd-Xml*(Fsd/Xls + Frd/Xlr) )/Xlr;
    irq = ( Frq-Xml*(Fsq/Xls + Frq/Xlr) )/Xlr;
    
    isdq = [isd; isq];
    isalphabeta = [cos(phi), -sin(phi); sin(phi), cos(phi)]*isdq;
    isabc = [1, 0; -0.5, sqrt(3)/2; -0.5, -sqrt(3)/2]*isalphabeta;
    
    irdq = [ird; irq];
    iralphabeta = [cos(phi), -sin(phi); sin(phi), cos(phi)]*irdq;
    irabc = [1, 0; -0.5, sqrt(3)/2; -0.5, -sqrt(3)/2]*iralphabeta;
    
    //TORQUE
    Me = (3/2)*p*(Fsd*isq - Fsq*isd)/wb
    
    Fmq = Xml*( Fsq/Xls + Frq /Xlr );
    Fmd = Xml*( Fsd/Xls + Frd /Xlr );
    
    //Differential equations
    xdot(1) = wb*( Usq - we/wb*Fsd + Rs/Xls*(Fmq - Fsq) );
    xdot(2) = wb*( Usd + we/wb*Fsq + Rs/Xls*(Fmd - Fsd) );
    xdot(3) = wb*( Urq - (we - wr)/wb*Frd + Rr/Xlr *(Fmq - Frq) );
    xdot(4) = wb*( Urd + (we - wr)/wb*Frq + Rr/Xlr *(Fmd - Frd ) );
    xdot(5) = p*(Me - D*wr - Mt)/J; 
    xdot(6) = isabc(1);
    xdot(7) = isabc(2);
    xdot(8) = isabc(3);
    xdot(9) = irabc(1);
    xdot(10) = irabc(2);
    xdot(11) = irabc(3);
    xdot(12) = Me;
    
    if t <= 5 then
    disp(Me);  
    end
    
    endfunction
    
    
    //Simulation parameter
    t = 0:0.001:5;
    t0 = 0;
    
    //Starting parameters
    y0 = [0;0;0;0;0;0;0;0;0;0;0;0]
    y = ode(y0,t0,t,list(AszinkronGep,Um,fHz));  
    
    //Graphs
    figure(1)
    plot(t,y(5,:), "linewidth", 3);
    xlabel("time [s]", "fontsize", 3, "color", "blue");
    ylabel("rpm [rpm]", "fontsize", 3, "color", "blue");
    
    figure(4)
    plot(t,y(12,:), "linewidth", 3);
    xlabel("time [s]", "fontsize", 3, "color", "blue");
    ylabel("torque [Nm]", "fontsize", 3, "color", "blue");
    

    我想要一个显示“我”随时间变化的图形。所以我写:xdot(12)=我,然后绘制它,但它看起来根本不应该这样。为了检查,我在函数末尾添加了“disp(Me)”,看看计算是否正确。是的,这些都是正确的值。为什么当我绘制它时,它会给我不同的值?

    1 回复  |  直到 8 年前
        1
  •  0
  •   luispauloml    8 年前

    如评论中所述, y(12) 是的积分 Me 结束 t . 如果你想的话 ,您只需将其区分开来:

    //after you run ode() and have y values
    h = t(2) - t(1);
    Me = diff(y(12,:)) ./ h;
    
    //plotting
    scf(); clf();
    
    subplot(2,1,1);
    xtitle("y(12,:)");
    plot2d(t,y(12,:));
    
    subplot(2,1,2);
    xtitle("Me");
    plot2d(t(1:$-1),Me);
    

    以下是输出:

    1

    推荐文章