G1=tf([1], [5 1])       % Eisagwgh prwths synarthshs metaforas

G2=tf([2], [5 2])       % Eisagwgh deytherhs synarthshs metaforas

figure(1)
bode(G1)
hold on
bode (G2)
hold off           % Digrammata Bode dyo synarthsevn metaforas sto idio diagramma

  
K=tf([2], [1 1]); % Estw synarthsh metaforas toy rithmisth
L=G1*K;  % loop transfer function
S=inv(1+L); % Sensitivity
T=1-S;      % complementary sensitivity
Marg=allmargin(G1*K);   % Ypologismos gain-phase margin


figure(2)
% tesseris grafikes parastaseis
   
    subplot(2,2,1)
    bode(S);
    subplot (2,2,2)
    bode(S*K);
    subplot (2,2,3)
    bode(T);
    subplot(2,2,4)
    step(feedback(G1*K,1))  % Feedback anatrofodothsh, step apokrish se bhmatikh epibolh
    hold off
%  Telos entolwn gia tesseris grafikes parastaseis    

norm(S,inf)       % Ypologismos normas apeiro




A=[-5 0 -2;-1 -4 1;-3 0 -5]      %Eisagwgh pinaka A

B=[0 1;2 9;1 2]						%Eisagwgh pinaka B

C=[2 4 5;1 2 4]						%Eisagwgh pinaka C

D=[0 0;0 0]								%Eisagwgh pinaka D

inv(A)									%Antistrofh pinaka A

A'											%Anastrofh pinaka A

A*B										%Pollaplasiasmos pinakwn A kai B

eig(A)									%Eyresh idiotimwn tou pinaka A

[P,V]=eig(A)							%O pinakas P dinei ta idiodianysmata toy A kai o pinakas V tis idiotimes

L=inv(P)*A*P							%O pinakas L einai diagwnios pinakas me tis idiotimes tou A

state=ss(A,B,C,D)						%Dhmiourgia systhmatos xwrou katastashs me onomasia "state" 

sys_tf=tf(state)                       %Metatroph systhmatos apo to xwro katastash se synarthsh metaforas

sys_zpk=zpk(state)                 %Metatroph systhmatos apo to xwro katastash se morfh mhdenikwn thesevn, polwn, enisxyshs

sys_tf=c2d(state,.01)                %Metatroph systhmatos apo to xwro katastash se synarthsh metaforas sto xwro z me xrono deimatolhpsias 0.01



size(state)								%Plhrofories gia to systhma xwrou katastashs "state"

isct(state)                             % Epistrefei 1 an to systhma einai synexes

isdt(state)                              % Epistrefei 1 an to systhma einai diakritoy xronou

pole(state)                             %Emfanizei toys poloys toy systhmatos

zero(state)                             %Emfanizei tis mhdenikes theseis toy systhmatos

obsv(state)								%Pinakas parathrhtikothtas tou systhmatos "state"

ctrb(state)								%Pinakas ry8misthkothtas toy systhmatos "state"

rank(ctrb(state))						%Ba8mos pinaka ry8misthkothtas toy systhmatos "state"

canstate=ss(L, inv(P)*B, C*P, D)	%Dhmiourgia tou systhmatos xwrou katastashs "canstate", pou antiproswpeyei to
											%antistoixo kanoniko systhma tou "state"
                                 
tfun=tf(state)							%Eyresh twn synarthsewn metaforas tou "state", kai topo8ethsh tous sthn metablhth "tfun"

figure(3)
step(state)								%Efarmogh bhmatikhs metabolhs sto systhma "state"

figure(4)
impulse(state)							%Efarmogh kroustikhs metabolhs sto systhma "state"

figure(5)
initial(state,[1,1,1])				%Dynamikh prosomoiwsh tou systhmatos "state", otan 3ekinaei apo tis arxikes syn8hkes
											%1,1,1
PII=lyap(A,eye(3))                  %O pinakas PII poy prokyptei prepei na exei oles tis eallsones orizoyses megalyteres toy 0 gia na einai to systhma 
                                            %eystathes 

K=place(A,B,[-4 -5 -6])                % Ypologismos toy pinaka K wste oi idiotimes toy pinaka A-B*K na briskontai sta shmeia poy 
                                        %apoteloyn to teleytaio orisma (dianysma) ths entolhs 
                                        
K = lqr(A,B,[1 0 0;0 1 0;0 0 1],[1 0;0 1])         % Ypologismos toy pinaka K wste na ypologistei to elaxisto toy problhmatos LQR

figure(6)
bode(state)								% Diagramma Bode

% Grafikh parastash megisths kai elaxisths idiazousas timhs
figure(7)
w_initial=0.01;
w_final=1000;
dw1=0.1;
dw2=0.1;
dw3=0.1;
w1=[w_initial:dw1:1];
w2=[1+dw2:dw2:10];
w3=[10+dw3:dw3:w_final];

w=[w1 w2 w3];
sigma(state,w),grid on
% Telos entolwn gia grafikh parastash megisths kai elaxisths idiazousas timhs

                                 