-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
02d8f4c
commit 86865a2
Showing
9 changed files
with
188 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
%============================================================================= | ||
% Copyright (c) 2023-present Allan CORNET (Nelson) | ||
%============================================================================= | ||
% This file is part of the Nelson. | ||
%============================================================================= | ||
% LICENCE_BLOCK_BEGIN | ||
% SPDX-License-Identifier: LGPL-3.0-or-later | ||
% LICENCE_BLOCK_END | ||
%============================================================================= | ||
function varargout = mpower(varargin) | ||
narginchk(2, 2) | ||
nargoutchk(0, 1) | ||
sysA = ss(varargin{1}); | ||
n = varargin{2}; | ||
mustBeNumeric(n, 2); | ||
mustBeInteger(n, 2); | ||
mustBeScalarOrEmpty(n, 2); | ||
mustBeNonempty(n, 2); | ||
if (n == 0) | ||
varargout{1} = ss(1); | ||
return; | ||
end | ||
sys = sysA; | ||
for k = 2:abs(n) | ||
sys = sys * sysA; | ||
end | ||
if n < 0 | ||
sys = inv(sys); | ||
end | ||
varargout{1} = sys; | ||
end | ||
%============================================================================= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
%============================================================================= | ||
% Copyright (c) 2023-present Allan CORNET (Nelson) | ||
%============================================================================= | ||
% This file is part of the Nelson. | ||
%============================================================================= | ||
% LICENCE_BLOCK_BEGIN | ||
% SPDX-License-Identifier: LGPL-3.0-or-later | ||
% LICENCE_BLOCK_END | ||
%============================================================================= | ||
function varargout = mpower(varargin) | ||
narginchk(2, 2) | ||
nargoutchk(0, 1) | ||
sysA = tf(varargin{1}); | ||
n = varargin{2}; | ||
mustBeNumeric(n, 2); | ||
mustBeInteger(n, 2); | ||
mustBeScalarOrEmpty(n, 2); | ||
mustBeNonempty(n, 2); | ||
if (n == 0) | ||
varargout{1} = ss(1); | ||
return; | ||
end | ||
|
||
if (n < 0) | ||
n = -n; | ||
sysA = inv(sysA); | ||
end | ||
sys = sysA; | ||
for i = 2:n | ||
sys = sys * sysA; | ||
end | ||
varargout{1} = sys; | ||
end | ||
%============================================================================= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
%============================================================================= | ||
% Copyright (c) 2023-present Allan CORNET (Nelson) | ||
%============================================================================= | ||
% This file is part of the Nelson. | ||
%============================================================================= | ||
% LICENCE_BLOCK_BEGIN | ||
% SPDX-License-Identifier: LGPL-3.0-or-later | ||
% LICENCE_BLOCK_END | ||
%============================================================================= | ||
A = [0 1; 0 0]; | ||
B = [0; 1]; | ||
C = [1 0]; | ||
D = 0; | ||
sys = ss(A, B, C, D); | ||
sys2 = sys ^ 3; | ||
REF_A = [0 1 0 0 0 0; | ||
0 0 1 0 0 0; | ||
0 0 0 1 0 0; | ||
0 0 0 0 1 0; | ||
0 0 0 0 0 1; | ||
0 0 0 0 0 0]; | ||
REF_B = [ 0; 0; 0; 0; 0; 1]; | ||
REF_C = [1 0 0 0 0 0]; | ||
REF_D = 0; | ||
assert_isequal(sys2.A, REF_A) | ||
assert_isequal(sys2.B, REF_B) | ||
assert_isequal(sys2.C, REF_C) | ||
assert_isequal(sys2.D, REF_D) | ||
%============================================================================= | ||
A = [0 1; 0 0]; | ||
B = [0; 1]; | ||
C = [1 0]; | ||
D = 0; | ||
sys = ss(A, B, C, D); | ||
sys2 = sys ^ -3; | ||
|
||
REF_A = [0 1 0 0 0 0 0; | ||
0 0 1 0 0 0 0; | ||
0 0 0 1 0 0 0; | ||
0 0 0 0 1 0 0; | ||
0 0 0 0 0 1 0; | ||
0 0 0 0 0 0 1; | ||
1 0 0 0 0 0 0]; | ||
REF_B = [ 0; 0; 0; 0; 0; 0; -1]; | ||
REF_C = [0 0 0 0 0 0 1] | ||
REF_D = 0; | ||
REF_E = [1 0 0 0 0 0 0; | ||
0 1 0 0 0 0 0; | ||
0 0 1 0 0 0 0; | ||
0 0 0 1 0 0 0; | ||
0 0 0 0 1 0 0; | ||
0 0 0 0 0 1 0; | ||
0 0 0 0 0 0 0]; | ||
assert_isequal(sys2.A, REF_A) | ||
assert_isequal(sys2.B, REF_B) | ||
assert_isequal(sys2.C, REF_C) | ||
assert_isequal(sys2.D, REF_D) | ||
assert_isequal(sys2.E, REF_E) | ||
%============================================================================= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
%============================================================================= | ||
% Copyright (c) 2023-present Allan CORNET (Nelson) | ||
%============================================================================= | ||
% This file is part of the Nelson. | ||
%============================================================================= | ||
% LICENCE_BLOCK_BEGIN | ||
% SPDX-License-Identifier: LGPL-3.0-or-later | ||
% LICENCE_BLOCK_END | ||
%============================================================================= | ||
num = [3 4]; | ||
den = [3 1 5]; | ||
Ts = 0.2; | ||
sys = tf(num, den, Ts); | ||
sys2 = sys ^ 3; | ||
R = evalc('display(sys2)'); | ||
REF = ' | ||
sys2 = | ||
27 z^3 + 108 z^2 + 144 z + 64 | ||
————————————————————————————————————————————————————————— | ||
27 z^6 + 27 z^5 + 144 z^4 + 91 z^3 + 240 z^2 + 75 z + 125 | ||
Sample time: 0.2000 seconds | ||
Discrete-time transfer function. | ||
'; | ||
assert_isequal(R, REF) | ||
%============================================================================= | ||
num = [3 4]; | ||
den = [3 1 5]; | ||
Ts = 0.2; | ||
sys = tf(num, den, Ts); | ||
sys2 = sys ^ -3; | ||
R = evalc('display(sys2)'); | ||
REF = ' | ||
sys2 = | ||
27 z^6 + 27 z^5 + 144 z^4 + 91 z^3 + 240 z^2 + 75 z + 125 | ||
————————————————————————————————————————————————————————— | ||
27 z^3 + 108 z^2 + 144 z + 64 | ||
Sample time: 0.2000 seconds | ||
Discrete-time transfer function. | ||
'; | ||
assert_isequal(R, REF) | ||
%============================================================================= |