Scilab图显示不正确的ode值

时间:2017-12-02 19:28:26

标签: function plot graph ode scilab

我正在尝试用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 个答案:

答案 0 :(得分:0)

正如评论中所述,y(12)Me超过t的积分。 如果你想要Me,你只需要区分它:

//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