summaryrefslogtreecommitdiff
path: root/3432/DEPENDENCIES/zpk_dk.sci
blob: 95b4e6c13728817d3442cfcfdc9366c25e900b2e (plain)
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//------------------------------------------------------------------
//------------------------------------------------------------------
//A function written by Deepti Khimani.
//Usage:-
//p=zpk_dk(sl)
//[p, z]=zpk_dk(sl)
//[p, z, k]=zpk_dk(sl)
//p:- Poles of the system
//z:- zeros of the system
//k:- DC gain of the system
//------------------------------------------------------------------
//------------------------------------------------------------------

function[pl,zr,k]=zpk_dk(sysmodel)
    [lhs,rhs]=argn(0)

    if rhs == 0 then
     disp(["p=zpk_dk(sl)";"[p, z]=zpk_dk(sl)";"[p, z, k]=zpk_dk(sl)"]);
     disp(["p:- Poles of the system";"z:- zeros of the system"]);
     disp("k:- DC gain of the system");
     return;
    end
    
    if typeof(sysmodel)=="rational" then
        sys=tf2ss(sysmodel);
        pl=spec(sys.A);
        zr=trzeros(sys);
        temp1=poly(zr,'s','roots')/poly(pl,'s','roots');
        temp2=sysmodel/temp1;
        temp3=tf2ss(temp2);
        k=temp3.D;
    elseif typeof(sysmodel)=="state-space" then
        pl=spec(sysmodel.A);
        zr=trzeros(sysmodel);
        g=ss2tf(sysmodel);
        temp1=poly(zr,'s','roots')/poly(pl,'s','roots');
        temp2=g/temp1;
        temp3=tf2ss(temp2);
        k=temp3.D
    else
        error("Wrong type of input argument.")
    end 
endfunction