-
Notifications
You must be signed in to change notification settings - Fork 4
/
xperm.sci
58 lines (51 loc) · 1.79 KB
/
xperm.sci
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function [output]=xperm(sys,perm)
//
//
// Calling Sequence
// sys = xperm(sys,Permutation)
//
// Parameters
// sys:-
// A state-space model of a linear dynamic system.
// Permuatation:-
// The vector Permutation should be a permutation of 1:nx where nx is the number of states in SYS.
//
// Description:-
// Function xperm
// Reorder states in state-space models
// sys = xperm(sys,P) reorders the states of the state-space model sys according to the permutation P.
// The vector P is a permutation of 1:NX, where NX is the number of states in sys.
// For information about creating state-space models, see ssrand,syslin.
//Examples
// aa=ssrand(2,3,2);
// ss=xperm(aa,[2 1])
// aa1=ssrand(3,6,8);
// ss1=xperm(aa1,[2 5 6 1 4 3 7 8])
//
//See Also
// ssrand,syslin.
//
//Authors
// Paresh Yeole
// emailid:-yeoleparesh@students.vnit.ac.in
[lhs,rhs]=argn(0);
if(rhs<2) then
error("xperm:Not enough input arguments.");
end
select typeof(sys)
case 'state-space' then
else
error("xperm:Undefined function xperm for given type of input arguments ");
end
[r,nx]=syssize(sys);
if ~(or(type(perm)==[1 5 8])) | isequal(gsort(perm),(1:nx))
error(msprintf(gettext("xperm:The second input argument of the xperm command must be a permutation of (1:%d)."),nx));
end
if(length(perm)<>nx) then
error(msprintf(gettext("xperm:The second input argument of the xperm command must be a permutation of (1:%d)."),nx));
end
sys.a = sys.a(perm,perm);
sys.b = sys.b(perm,:);
sys.c = sys.c(:,perm);
output=sys;
endfunction