Está en la página 1de 2

%Este programa resolverá y graficará una EDO de segundo orden por métodos

%numéricos
clear
clc
%Datos
H=9.94; %constante de inercia (MJ/MVA)
f=60; %frecuencia (Hz)
Pm=3; %Potencia mecánica (pu)
P1=6; %Potencia eléctrica (pu)
P2=0;
P3=4.5;
P4=6;
Td=0; %Torque de fricción (pu)
t1=1;
t2=1.6;
t3=1.7;
t0=0; %Tiempo inicial
t4=5; %Tiempo final
x10=pi/6; %x1(0)
x20=0; %x2(0)=x1'(0)
h=0.001; %Paso
tf=t1;
t(1)=t0;
Pel=P1;
k=1;
kk=0;
y1(1)=x10;
y2(1)=x20;
while 1
A=H/(pi*f);
B=Pm-Pel;
C=Td;
%Acondicionando las funciones
f1=@(t,x1,x2) x2;
f2=@(t,x1,x2) B/A-(C/A)*x2;
%Algoritmo de Euler para EDO de segundo orden
while t(k)<tf
t(k+1)=t0+(k-kk)*h;
y1(k+1)=y1(k)+h*f1(t(k),y1(k),y2(k));
y2(k+1)=y2(k)+h*f2(t(k),y1(k),y2(k));
k=k+1;
end
kk=k-1;
if t(k)<t2
Pel=P2;
t0=t(k);
tf=t2;
elseif t(k)<t3
Pel=P3;
t0=t(k);
tf=t3;
else
Pel=P4;
t0=t(k);
tf=t4;
end
if t(k)>=t4
break
end
end

%Graficando
subplot(1,2,1)
plot(t,y1,'-b')
title('Dinámica del GS','fontsize',12)
xlabel('Tiempo (s)')
ylabel('Ángulo del rotor (rad elect)')
subplot(1,2,2)
plot(t,120*pi+y2,'-r') %
title('Dinámica del GS','fontsize',12)
xlabel('Tiempo (s)')
ylabel('Velocidad del rotor (rad elect/s)')
grid on

También podría gustarte