Escolar Documentos
Profissional Documentos
Cultura Documentos
Descritivo de Operação
MATLAB
1 12/03/08
MANUAL MATLAB
2 12/03/08
MANUAL MATLAB
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
-3 -2 -1 0 1 2 3
............................................................................ 19
2. SINAIS DE TESTES.................................................................................................................................. 19
Sinais de teste – degrau .................................................................................................................... 19
Sinais de teste – rampa ..................................................................................................................... 20
Sinais de teste – parábola ................................................................................................................. 22
3. COMPORTAMENTO DOS SISTEMAS ......................................................................................................... 23
Root – extrair raiz ............................................................................................................................ 23
Pole – definir o pólo da funcao transferencia .................................................................................. 23
4. FUNÇÃO DE TRANSFERÊNCIA ................................................................................................................. 23
Transformar equação diferencial em função de transferência (dsolve,simple,pretty) ..................... 23
5. DIAGRAMA DE BODE ............................................................................................................................. 25
grafico .............................................................................................................................................. 25
6. MODELAGEM NO ESPAÇO DE ESTADOS ................................................................................................. 25
Achar a função de transferencia....................................................................................................... 27
A. OPERACOES MATLAB
1. Funções Matlab
>> diary('06_08_2005')
Matriz Simples
>> A=[123;456;789]
A=
123
456
789
3 12/03/08
MANUAL MATLAB
>> gera
a=
123
456
789
x=
Abs – absoluto
>> x=abs(-1)
x=
a=
111
222
333
>> a(2,1)=2*a(3,1)
a=
111
666
333
111
666
333
>> r=[10];
>> a=[a;r]
a=
111
666
4 12/03/08
MANUAL MATLAB
333
10
111
666
333
10
>> a=a(1:3,:)
a=
111
666
333
b=
1 2 3 4 5 6
>> b=[1:2:3:4:5:6;1:2:3:4:5:6]
Warning: Colon operands must be real scalars.
b=
1 2 3 4 5 6
1 2 3 4 5 6
A a ans b r x
5 12/03/08
MANUAL MATLAB
>> 2*50
ans =
100
>> 2*ans
ans =
200
Divisão
>> 1/4
ans =
0.2500
>> 4\1
ans =
0.2500
General.
ctrlpref - Set Control System Toolbox preferences.
ltimodels - Detailed help on the various types of LTI models.
ltiprops - Detailed help on available LTI model properties.
6 12/03/08
MANUAL MATLAB
LSIM(SYS,U,T) plots the time response of the LTI model SYS to the
input signal described by U and T. The time vector T consists of
regularly spaced time samples and U is a matrix with as many columns
as inputs and whose i-th row specifies the input value at time T(i).
For example,
a=
1 2 3
4 5 6
7 8 9
>> d=a'
d=
1 4 7
2 5 8
3 6 9
1 2 3
4 5 6
7 8 9
>> d=a'
d=
1 4 7
2 5 8
3 6 9
>> c=a + d
c=
2 6 10
6 10 14
10 14 18
7 12/03/08
MANUAL MATLAB
x=
-1
0
2
>> y=x-1
y=
-2
-1
1
Matriz – multiplicação
>> x=[-1 0 2]'
x=
-1
0
2
>> y=x-1
y=
-2
-1
1
>> x'*y
ans =
Função pi
>> pi
ans =
3.1416
Matriz – divisão
Função clear
Limpar uma variável
8 12/03/08
MANUAL MATLAB
>> b=[13,14,15]
b=
13 14 15
>> clear b
>> who
a ans c d x y
>> clear
>> who
>>
Matriz – exponencial
>> b = [2,4;3,6]
b=
2 4
3 6
>> b^2
ans =
16 32
24 48
x=
-1
0
2
>> x*2
ans =
-2
0
4
9 12/03/08
MANUAL MATLAB
y=
4 5 6
z=
4 10 18
ans =
1
0
4
>> x
x=
1 2 3
>> y
y=
4 5 6
>> clear z
>> z= x.^y
z=
1 32 729
>> z=2.^[x y]
z=
2 4 8 16 32 64
Operadores logicos
>> 1==1 & 4==3
ans =
10 12/03/08
MANUAL MATLAB
ans =
vetor - incremento
incrementa vetor de 1 ate 5 de 1 em 1
>> x=1:5
x=
1 2 3 4 5
x=
1 3 5 7 9
vetor – decremento
Decrementa x de 5 ate 1 de 1 em 1
>> x=5:-1:1
x=
5 4 3 2 1
ans =
a=
1 2 3
4 5 6
7 8 9
>> a(3,3)=a(1,3)+a(3,1)
a=
1 2 3
4 5 6
7 8 10
>> a(1,3)
11 12/03/08
MANUAL MATLAB
ans =
>> a(3,1)
ans =
exemplo 2
>> a=[1,2,3,4,5;6,7,8,9,10;11,12,13,14,15;16,17,18,19,20;21,22,23,24,25]
a=
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
ans =
3
8
13
18
23
ans =
4 5
9 10
14 15
19 20
24 25
exemplo 3
a=
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
ans =
12 12/03/08
MANUAL MATLAB
1 2 3 4 5
11 12 13 14 15
21 22 23 24 25
Matriz - inserir 1
b=
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Matriz – inserir 0
>> b= zeros(5)
b=
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
a=
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
21 22 23 24 25
>> b=zeros(5)
b=
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
>> b(1:1:3,4:5)=a(5:-1:3,1:2)
13 12/03/08
MANUAL MATLAB
b=
0 0 0 21 22
0 0 0 16 17
0 0 0 11 12
0 0 0 0 0
0 0 0 0 0
Gráficos- plot
>> y=[0.0,0.48,0.84,1.0,0.91,0.6,0.14];
>> plot (y)
y=
1 2 3
4 5 6
7 8 9
>> x=[1,2,3]
x=
1 2 3
14 12/03/08
MANUAL MATLAB
1
1 1.2 1.4 1.6 1.8 2 2.2 2.4 2.6 2.8 3
x=
1 2 3
4 5 6
7 8 9
>> y=x'
y=
1 4 7
2 5 8
3 6 9
1
1 2 3 4 5 6 7 8 9
15 12/03/08
MANUAL MATLAB
Gráficos – mesh
>> x=[1,2,3;4,5,6;7,8,9]
x=
1 2 3
4 5 6
7 8 9
>> y=x'
y=
1 4 7
2 5 8
3 6 9
>> z=x.*exp(-x.^2-y.^2);
>> mesh(x,y,z)
0.5
-0.5
2
1 2
0 1
0
-1 -1
-2 -2
16 12/03/08
MANUAL MATLAB
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
-3 -2 -1 0 1 2 3
i=
>> x(i)
ans =
25
outro exemplo
>> for i=1:8,
for j=1:8,
a(i,j)=i+j;
b(i,j)=i-j;
end
end
>> a
a=
2 3 4 5 6 7 8 9
3 4 5 6 7 8 9 10
4 5 6 7 8 9 10 11
5 6 7 8 9 10 11 12
6 7 8 9 10 11 12 13
7 8 9 10 11 12 13 14
8 9 10 11 12 13 14 15
9 10 11 12 13 14 15 16
>> b
b=
0 -1 -2 -3 -4 -5 -6 -7
1 0 -1 -2 -3 -4 -5 -6
2 1 0 -1 -2 -3 -4 -5
17 12/03/08
MANUAL MATLAB
3 2 1 0 -1 -2 -3 -4
4 3 2 1 0 -1 -2 -3
5 4 3 2 1 0 -1 -2
6 5 4 3 2 1 0 -1
7 6 5 4 3 2 1 0
a=
2 -1 0 0 0
-1 2 -1 0 0
0 -1 2 -1 0
0 0 -1 2 -1
0 0 0 -1 2
num =
10
p1 =
20000 200 1
>> p2=[443 1]
p2 =
18 12/03/08
MANUAL MATLAB
443 1
>> den=conv(p1,p2)
den =
>> gma=tf([num],[den])
Transfer function:
10
-------------------------------------
8.86e006 s^3 + 108600 s^2 + 643 s + 1
0.8
0.6
0.4
0.2
-0.2
-0.4
-0.6
-0.8
-1
-3 -2 -1 0 1 2 3
2. Sinais de Testes
Transfer function:
5
--------------
s^2 + 2 s + 10
>> step(g)
19 12/03/08
MANUAL MATLAB
Step Response
0.7
0.6
0.5
0.4
Amplitude
0.3
0.2
0.1
0
0 1 2 3 4 5 6
Time (sec)
4.5
3.5
2.5
2
2 2.5 3 3.5 4 4.5 5
>> hold on
>> g=tf([5],[1 2 10])%entrada do sistema e criacao da funcao transferencia
Transfer function:
5
--------------
s^2 + 2 s + 10
>> y=lsim(g,u,t);
Warning: Simulation will start at the nonzero initial time T(1).
> In lti.lsim at 91
>> plot (t,y,'y')
4.5
3.5
2.5
1.5
0.5
0
2 2.5 3 3.5 4 4.5 5
outro exemplo
>> t=0:0.01:5;%0 ponto de inicio, 1/100 divisoes, 5 maximo
20 12/03/08
MANUAL MATLAB
>> k=1;
>> u=k.*t;%fazendo a coordenada = abcissa
>> y=lsim(g,u,t);
>> plot (t,y,'b*')
>> hold on
>> k=0:0.01:5;
>> plot (t,k,'b*')
4.5
3.5
2.5
1.5
0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
outro exemplo
Transfer function:
1
-
s
Transfer function:
1
-
s
Step Response
1.4
1.2
0.8
Amplitude
0.6
0.4
0.2
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Time (sec)
>> hold on
>> g=tf([5],[1 2 10])%entrada do sistema e criacao da funcao transferencia
Transfer function:
5
--------------
21 12/03/08
MANUAL MATLAB
s^2 + 2 s + 10
>> t=0:1/100:1;
>> u=step(degrau);
>> y=lsim(g,u,t);
>> plot (t,y,'r')
Step Response
1.4
1.2
0.8
Amplitude
0.6
0.4
0.2
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Time (sec)
Transfer function:
1
-
s
>> step(rampa)%1/s^2
Step Response
1.4
1.2
0.8
Amplitude
0.6
0.4
0.2
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Time (sec)
>> hold on
>> t=0:1/100:1;
>> u=step(rampa);%1/s^3 ???
>> g=tf([5],[1 2 10])%entrada do sistema e criacao da funcao transferencia
Transfer function:
5
--------------
s^2 + 2 s + 10
>> y=lsim(g,u,t);
>> plot (t,y,'r')
22 12/03/08
MANUAL MATLAB
Step Response
1.4
1.2
0.8
Amplitude
0.6
0.4
0.2
0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Time (sec)
ans =
0
2
-1
sistema do tipo 1 (uma raiz)
Transfer function:
1
---------------
s^3 + s^2 - 2 s
ans =
0
-2
1
4. função de transferência
23 12/03/08
MANUAL MATLAB
matlab
>> y=dsolve('a*D2y+b*Dy+c*y=1','y(0)=0,Dy(0)=0')
y=
-1/2*exp(-1/2*(b-(b^2-4*c*a)^(1/2))/a*t)*(b+(b^2-4*c*a)^(1/2))/(b^2-4*c*a)^(1/2)/c+1/2*exp(-1/2*(b+(b^2-
4*c*a)^(1/2))/a*t)*(b-(b^2-4*c*a)^(1/2))/(b^2-4*c*a)^(1/2)/c+1/c
>> s=laplace(y)
s=
-1/2*(b+(b^2-4*c*a)^(1/2))/(b^2-4*c*a)^(1/2)/c/(s+1/2/a*(b-(b^2-4*c*a)^(1/2)))+1/2*(b-(b^2-
4*c*a)^(1/2))/(b^2-4*c*a)^(1/2)/c/(s+1/2/a*(b+(b^2-4*c*a)^(1/2)))+1/c/s
>> ss=simple(s)
ss =
1/(s^3*a+c*s+s^2*b)
>> pretty(ss)
1
-----------------
3 2
s a+cs+s b
segunda parte
u=
-(-1+f)/e^2*d*exp(-e/d*t)+t/e-t/e*f+d*(-1+f)/e^2
>> s=laplace(u)
s=
-d*(-1+f)/e^2/(s+e/d)+1/e/s^2-1/e*f/s^2+d*(-1+f)/e^2/s
>> ss=simple(s)
ss =
(1-f)/(s*d+e)/s^2
>> pretty(ss)
1-f
24 12/03/08
MANUAL MATLAB
------------
2
(s d + e) s
5. Diagrama de bode
grafico
>> g=tf([100],[1 6 100])
Transfer function:
100
---------------
s^2 + 6 s + 100
>> bode(g)
Bode Diagram
20
0
Magnitude (dB)
-20
-40
-60
-80
0
-45
Phase (deg)
-90
-135
-180
-1 0 1 2 3
10 10 10 10 10
Frequency (rad/sec)
A=
0 1
-2 -3
>> B=[0;1]
25 12/03/08
MANUAL MATLAB
B=
0
1
>> C=[1 0]
C=
1 0
>> C=[1 0]
C=
1 0
>> D=0
D=
>> impulse(A,B,C,D)
Impulse Response
0.25
0.2
0.15
Amplitude
0.1
0.05
0
0 1 2 3 4 5 6
Time (sec)
>>
>> [num,den]=ss2tf(A,B,C,D)
num =
0 -0.0000 1.0000
den =
1 3 2
>> printsys(num,den)
26 12/03/08
MANUAL MATLAB
num/den =
-4.4409e-016 s + 1
------------------
s^2 + 3 s + 2
m=
>> c=2
c=
>> k=1
k=
A=
0 1.0000
-0.2000 -0.4000
>> B=[0;1/m]
B=
0
0.2000
>> C=[1 0]
C=
1 0
>> D=0
D=
>> num=[1]
num =
27 12/03/08
MANUAL MATLAB
>> den=[m c k]
den =
5 2 1
>> [A,B,C,D]=tf2ss(num,den)
A=
-0.4000 -0.2000
1.0000 0
B=
1
0
C=
0 0.2000
D=
>> [num,den]=ss2tf(A,B,C,D)
num =
0 0.0000 0.2000
den =
>> g=tf(num,den)
Transfer function:
1.11e-016 s + 0.2
-----------------
s^2 + 0.4 s + 0.2
28 12/03/08