You are on page 1of 12

Experiencia 2

Modelacin de sistemas utilizando


MATLAB
2.1.

Objetivos.Modelar sistemas lineales invariantes en el tiempo.


Utilizar los diferentes comandos que proporciona MATLAB para realizar simulaciones
de sistemas de control.
Utilizar herramientas computacionales provistas por MATLAB para la conexin,
conversin de modelos LTI.

2.2. Trabajo Preparatorio.Se tiene un circuito serie RLC alimentado por una fuente v(t) entrada y Vc(t) tensin en
el capacitor de salida

2.2.1.

Obtener la ecuacin diferencial que define el sistema

Vcc=

2.2.2.

Obtener la funcin de transferencia del sistema


Hallamos la transformada de cada una de las acuaciones de 2.3.1
Datos arbitrarios: R=3 ohms, L=1 H, C=1/2 F,
LsI(s)+RI(s)+

I(s)

I(s)

2.2.3.

Obtener analticamente el modelo en variables de estado(no realizar)

2.2.4.

Obtener analticamente Vc(t) para una entrada escaln unitario para valores RLC
asumidos por el estudiante. (ntese que la entrada paso es la integral de una
entrada impulso)

Escaln unitario :

Por lo tanto reemplazando los valores arbitrarios

X(s)=

X(s)=

Hallamos la transformada inversa de laplace:

2.2.5.

Con la ayuda del Excel presente los grficos para una entrada escaln unitario en
lazo abierto.
%Funcin escaln
t=0:0.01:20;
y=exp(-2*t)- 2*exp(-t)+1;
u=0.1;
plot(t,y,t,u)

2.3.
2.3.1.

Trabajo Experimental.Obtenga el modelo en espacio de estado, zpk, respuesta en frecuencia si es


posible del sistema del trabajo preparatorio.

TF : modelo a funcin de transferencia:


>>sys=tf(sys)
Transfer function:
2s
----------------s^3 + 3 s^2 + 2 s
ZPK : modelo ceros polos ganancia
>> sys=zpk(sys)
Zero/pole/gain:
2s
------------s (s+2) (s+1)
SS : modelo a espacio estados:
>> sys=ss(sys)
a=
x1 x2 x3
x1 0 0 0
x2 0 -2 1
x3 0 0 -1
b=
u1
x1
0
x2
0
x3 1.414
c=

y1

x1 x2 x3
0 1.414
0

d=
u1
y1 0
FRD : modelo de respuesta a frecuencia

2.3.2.

Obtener la respuesta en lazo abierto y cerrado para las entradas: impulso, paso,
rampa, senoidal. Solon abierto

clc
%pregunta2.4.2. respuesta para las siguientes entradas:
disp('Respuesta a impulso')
num=[2 5];
den=[1 2 5];
%impulse(num,dem)
subplot(2,2,1),impulse(num,den),grid
disp('Respuesta paso')
%step(num,den)
subplot(2,2,2),step(num,den),grid
disp('Respuesta a entrada rampa')
num1=[1];
den1=[1 0 0];
a=tf(num,den)
b=tf(num1,den1)
sys=series(a,b)
%impulse(sys)
subplot(2,2,3),impulse(sys),grid
disp('Respuesta a entrada senoidal')
num1=[1];
den1=[1 0 1];
a=tf(num,den);
b=tf(num1,den1);
sys=series(a,b)
%impulse(sys)
subplot(2,2,4),impulse(sys),grid

2.3.3.

Obtenga la ecuacin diferencial que representa al sistema y la funcin de


transferencia del siguiente circuito:
+
+

Su ecuacin diferencial es:


;

; I=

Se toma la transformada de laplace:


I(s)R1+ (s)R2
(s)

2.4.
2.4.1.

Informe.Empleando lazos y estructura de control de flujo, elabore un programa que permita


obtener sobre un mismo grafico la respuesta escaln en lazo abierto para cinco
valores diferentes del parmetro a del sistema dado por la siguiente funcin de
transferencia:
a
s4
Para respuesta step
G (s)

clc
%informe 2.5.2.
disp('
INFORME DE LAB CONTROL N2')
disp('
--------------------------')
a1=input('ingrese a1= ');
a2=input('ingrese a2= ');
a3=input('ingrese a3= ');
a4=input('ingrese a4= ');
a5=input('ingrese a5= ');
t=0:0.2:7;
G1=(-a1)*0.25.*(exp(-4*t)-1);
G2=(-a2)*0.25.*(exp(-4*t)-1);
G3=(-a3)*0.25.*(exp(-4*t)-1);
G4=(-a4)*0.25.*(exp(-4*t)-1);
G5=(-a5)*0.25.*(exp(-4*t)-1);
plot(t,G1,'r',t,G2,'b',t,G3,'g',t,G4,'y',t,G5);grid
xlabel('eje tiempo'),ylabel('eje y')
legend('f1','f2','f3','f4','f5',0)
title('CONTROL DE FLUJO')
grid

Comentarios y conclusiones:.
Se aprendieron algunas herramientas en Matlab para utilizarlas en la reduccin de
diagramas de bloques.
Se aprendi en esta prctica a crear modelos ceros-polos-ganancia o convertir
modelos de funcin de transferencia, la cual es de mucha importancia para Control de
sistemas y Procesamiento de la seal.
La importancia de esta prctica, es que adems de anexar una lista de comandos en
un lenguaje de instrucciones se busca en general el entendimiento del proceso, las
funciones que ejercen los comandos digitados por el usuario, tienen una funcin
determinada, lo que se busca es facilitar estos procesos que requieren que se
resuelvan a papel y lpiz, pero con solo entender lo que se necesita realizar, podemos
lograr estos clculos utilizando de manera esencial la herramienta Matlab.

2.5.

Bibliografa.-

The Math Works Inc, Manuales MATLAB.


Diagram de mason
PROGRAMA EN MATLAB SOBRE LA FORMULA DE MASON
function [Num,Den] = mason(NetFile,Start,Stop)
fid=fopen(NetFile); if (fid==-1)
fprintf('\n*** File, %s, not found ***\n\n',NetFile)
return
end
Net=[]; line_number=0; Coeff_Names={}; while 1 line_number=line_number+1; x=fscanf(fid,'%d',3);
Coeff=fscanf(fid,'%s\n',1);
if isempty(x) break
end
Net(line_number,:)=transpose(x);
Coeff_Names{line_number}= Coeff;
end
fclose(fid);
temp=size(Net);
Number_Coeff=temp(1);
[PathCoeffList,PathNodeList]=findpaths(Start,Stop,[],[],Net);
LoopCoeffList=[];
LoopNodeList=[];
for index=1:Number_Coeff;
[FoundLoops,FoundNodes]=findpaths(index,index,[],[],Net);
LoopCoeffList=[LoopCoeffList;FoundLoops]; LoopNodeList=[LoopNodeList;FoundNodes]; end
[LoopCoeffList,LoopNodeList]=RemoveDuplicateLoops(LoopCoeffList,LoopNodeList);
temp=size(PathCoeffList);
NumberPaths=temp(1);
if (NumberPaths==0);
fprintf('\n*** There are no paths connecting those nodes ***\n')
return
end
for index=1:NumberPaths

Coeff=PathCoeffList(index,:);
P{index}.Coeff=Coeff(1:sum(Coeff>0));
Node=PathNodeList(index,:);
P{index}.Node=[Node(1:sum(Coeff>0)),Stop];
end
temp=size(LoopCoeffList);
NumberLoops=temp(1);
L{1}.NumberLoops=NumberLoops;
for index=1:NumberLoops
Coeff=LoopCoeffList(index,:);
L{1}.Coeff{index}=Coeff(1:sum(Coeff>0));
Node=LoopNodeList(index,:);
L{1}.Node{index}=[Node(1:sum(Coeff>0)),Node(1)];
end
=1;
while 1
n=n+1;
L{n}.NumberLoops=0;
for first=1:L{1}.NumberLoops
for second=1:L{n-1}.NumberLoops
if not(AreTouchingLoops(L{1}.Node{first},L{n-1}.Node{second}))
Duplicate=0;
for index=1:L{n}.NumberLoops
if IsSameLoop([L{1}.Coeff{first}, L{n-1}.Coeff{second}],L{n}.Coeff{index})
Duplicate=1;
end
end
if (Duplicate==0)
L{n}.NumberLoops=L{n}.NumberLoops+1;
L{n}.Coeff{(L{n}.NumberLoops)}=[L{1}.Coeff{first}, L{n-1}.Coeff{second}];
L{n}.Node{(L{n}.NumberLoops)}=[L{1}.Node{first}, L{n-1}.Node{second}];
end
end
end
end
if (L{n}.NumberLoops==0)
break
end
end
fprintf('\n-- Network Info --\n')
fprintf('Net File : ');fprintf(NetFile);fprintf('\n');
fprintf('Start Node : %d\n',Start);
fprintf('Stop Node : %d\n',Stop);
fprintf('\n----- Paths -----\n')
for pathn=1:length(P)
fprintf('P%d : ',pathn);
fprintf('%d ',P{pathn}.Coeff);
fprintf('\n');
end
for loop_order=1:length(L)-1
fprintf('\n- Order %d Loops -\n',loop_order)
for loop_number=1:L{loop_order}.NumberLoops
fprintf('L%d%d : ',loop_order,loop_number)
fprintf('%d ',L{loop_order}.Coeff{loop_number})
fprintf('\n')
end
end
Num='';
for pathn=1:length(P)

Num=sprintf('%s%s*(1', Num, CoeffToString(P{pathn}.Coeff)); % Pn*(1 ..


for order=1:length(L)-1
if (rem(order,2)==1)
Num=sprintf('%s-',Num);
else
Num=sprintf('%s+',Num);
end
Num=[Num,PrintSumsNotTouching(L,order,P{pathn}.Node)];
end
Num=sprintf('%s)+',Num); %
end
Num=Num(1:length(Num)-1);
Den='1';
for order=1:length(L)-1 %
if (rem(order,2)==1)
Den=sprintf('%s-',Den);
else
Den=sprintf('%s+',Den);
end
Den=[Den,PrintSumsNotTouching(L,order,[9999999 999999])];
end
fprintf('\nThe variables returned are strings describing\n')
fprintf('the numerator and Denominator of the transfer equation.\n')
fprintf('If you have the symbolic toolbox, use Denominator=sym(Denominator)\n');
fprintf('and Numerator=sym(Numerator) to make these symbolic equations.\n')
fprintf('You can now use simple(Numerator/Denominator) to boil the whole\n')
fprintf('thing down. You could also use simple(Numerator) to simplify the\n')
fprintf('Numerator on it'' own.\n\n')
for coeff_num=length(Coeff_Names):-1:1;
orig=sprintf('c%d',Net(coeff_num,1));
Den=strrep(Den,orig,Coeff_Names{coeff_num});
Num=strrep(Num,orig,Coeff_Names{coeff_num});
end %
function Touching=AreTouchingLoops(Nodes1,Nodes2)
Loop1Length=sum(Nodes1>0);
Loop2Length=sum(Nodes2>0);
for first=1:Loop1Length
for second=1:Loop2Length
if (Nodes1(first)==Nodes2(second))
Touching=1;
return;
end
end
end
Touching=0;
function StrMult=CoeffToString(Coefficients)
N=length(Coefficients);
StrMult=sprintf('c%d',Coefficients(1));
for n=2:N
StrMult=[StrMult, sprintf('*c'),sprintf('%d',Coefficients(n))];
end
function [PathUp,NodesUp]=findpaths(StartNode,StopNode,Path,Nodes,Net)
temp=size(Net);
NumberCoeff=temp(1,1);
PathUp=[];
NodesUp=[];
for index=1:NumberCoeff
if not(isempty(Nodes))

10

if (sum(Nodes==index)>1)
PathUp=[];
return
end
end
end
if ((StartNode==StopNode) & (length(Path>1)))
PathUp=Path;
NodesUp=Nodes;
return
end
for index=1:NumberCoeff
if (StartNode==Net(index,2))
[FoundPath,FoundNodes]=findpaths(Net(index,3),StopNode,[Path,Net(index,1)],
[Nodes,StartNode],Net);
if not(isempty(FoundPath))
PathUp=[PathUp;[FoundPath,zeros(1,NumberCoeff+1-length(FoundPath))]];
NodesUp=[NodesUp;[FoundNodes,zeros(1,NumberCoeff+1-length(FoundPath))]];
end
end
end
function Same=IsSameLoop(Loop1,Loop2)
Loop1Length=sum(Loop1>0);
Loop2Length=sum(Loop2>0);
if (Loop1Length~=Loop2Length)
Same=0;
return
end
if (sum(abs(sort(Loop1)-sort(Loop2)))==0)
Same=1;
else
Same=0; %
function Str=PrintSumsNotTouching(L,order,Pnodes)
No_NonTouching=1;
Str=('(');
for n=1:L{order}.NumberLoops
if not(AreTouchingLoops(Pnodes,L{order}.Node{n})) Str=sprintf('%s
%s+',Str,CoeffToString(L{order}.Coeff{n}));
No_NonTouching=0; %
end
end
Str=Str(1:(length(Str)-1));
Str=sprintf('%s)',Str);
if No_NonTouching==1
end
function [LoopList,NodeList]=RemoveDuplicateLoops(LoopList,NodeList);
temp=size(LoopList);

11

NumberLoops=temp(1);
first=1;
while (first<=NumberLoops)
second=first+1;
while (second<=NumberLoops)
if (IsSameLoop(LoopList(first,:),LoopList(second,:))==1)
LoopList=[LoopList(1:second-1,:);LoopList(second+1:NumberLoops,:)];
NodeList=[NodeList(1:second-1,:);NodeList(second+1:NumberLoops,:)];
NumberLoops=NumberLoops-1;
else
second=second+1;
end
first=first+1;
end

12

You might also like