init
This commit is contained in:
18
FOTF Toolbox/@ppoly/collect.m
Normal file
18
FOTF Toolbox/@ppoly/collect.m
Normal file
@ -0,0 +1,18 @@
|
||||
function p=collect(p)
|
||||
% collect - collect like terms in ppoly objects
|
||||
%
|
||||
% p=collect(p)
|
||||
%
|
||||
% p - a ppoly object
|
||||
|
||||
% Copyright (c) Dingyu Xue, Northeastern University, China
|
||||
% Last modified 18 May, 2022
|
||||
a=p.a; na=p.na;
|
||||
[na,ii]=sort(na,'descend'); a=a(ii); ax=diff(na); key=1;
|
||||
for i=1:length(ax)
|
||||
if abs(ax(i))<=1e-10
|
||||
a(key)=a(key)+a(key+1); a(key+1)=[]; na(key+1)=[];
|
||||
else, key=key+1; end
|
||||
end
|
||||
ii=find(abs(a)~=0); a=a(ii); na=na(ii); p=ppoly(a,na);
|
||||
end
|
23
FOTF Toolbox/@ppoly/disp.m
Normal file
23
FOTF Toolbox/@ppoly/disp.m
Normal file
@ -0,0 +1,23 @@
|
||||
function str=disp(p)
|
||||
% collect - collect like terms in ppoly objects
|
||||
%
|
||||
% p=collect(p)
|
||||
%
|
||||
% p - a ppoly object
|
||||
|
||||
% Copyright (c) Dingyu Xue, Northeastern University, China
|
||||
% Last modified 18 May, 2022
|
||||
np=p.na; p=p.a;
|
||||
if isempty(np), p=0; np=0; end
|
||||
P=''; [np,ii]=sort(np,'descend'); p=p(ii);
|
||||
for i=1:length(p)
|
||||
P=[P,'+',num2str(p(i)),'*s^{',num2str(np(i)),'}'];
|
||||
end
|
||||
P=P(2:end); P=strrep(P,'s^{0}',''); P=strrep(P,'+-','-');
|
||||
P=strrep(P,'^{1}',''); P=strrep(P,'+1*s','+s');
|
||||
P=strrep(P,'*+','+'); P=strrep(P,'*-','-');
|
||||
P=strrep(P,'-1*s','-s'); nP=length(P);
|
||||
if nP>=3 && isequal(P(1:3),'1*s'), P=P(3:end); end
|
||||
if P(end)=='*', P(end)=''; end
|
||||
if nargout==0, disp(P), else, str=P; end
|
||||
end
|
12
FOTF Toolbox/@ppoly/eq.m
Normal file
12
FOTF Toolbox/@ppoly/eq.m
Normal file
@ -0,0 +1,12 @@
|
||||
function key=eq(p1,p2)
|
||||
% eq - test whether two PPOLY objects are equal or not
|
||||
%
|
||||
% key=p1==p2
|
||||
%
|
||||
% p1, p2 - the two PPOLY objects
|
||||
% key = 1 for equal, otherwise key = 0
|
||||
|
||||
% Copyright (c) Dingyu Xue, Northeastern University, China
|
||||
% Last modified 18 May, 2022
|
||||
g=collect(p1-p2); key=isempty(g.a);
|
||||
end
|
13
FOTF Toolbox/@ppoly/freqw.m
Normal file
13
FOTF Toolbox/@ppoly/freqw.m
Normal file
@ -0,0 +1,13 @@
|
||||
function H=freqw(p,w)
|
||||
% freqw - get frequency response of ppoly object
|
||||
%
|
||||
% H=freqw(p,w)
|
||||
%
|
||||
% p - a ppoly object
|
||||
% w - frequency vector
|
||||
% H - frequency response data
|
||||
|
||||
% Copyright (c) Dingyu Xue, Northeastern University, China
|
||||
% Last modified 18 May, 2022
|
||||
for i=1:length(w), H(i)=p.a(:).'*(1i*w(i)).^p.na(:); end
|
||||
end
|
19
FOTF Toolbox/@ppoly/get.m
Normal file
19
FOTF Toolbox/@ppoly/get.m
Normal file
@ -0,0 +1,19 @@
|
||||
function p1=get(varargin)
|
||||
% get - get fields from ppoly object
|
||||
%
|
||||
% a=get(p,'a') or na=get(p,'na')
|
||||
|
||||
% Copyright (c) Dingyu Xue, Northeastern University, China
|
||||
% Last modified 18 May, 2022
|
||||
p=varargin{1};
|
||||
if nargin==1
|
||||
s=sprintf('%f ,',p.a); disp([' a: [' s(1:end-1) ']'])
|
||||
s=sprintf('%f ,',p.na); disp([' na: [' s(1:end-1) ']'])
|
||||
elseif nargin==2, key=varargin{2};
|
||||
switch key
|
||||
case 'a', p1=p.a; case 'na', p1=p.na;
|
||||
otherwise, error('Wrong field name used'),
|
||||
end
|
||||
else, error('Wrong number of input argumants');
|
||||
end
|
||||
end
|
11
FOTF Toolbox/@ppoly/isppoly.m
Normal file
11
FOTF Toolbox/@ppoly/isppoly.m
Normal file
@ -0,0 +1,11 @@
|
||||
function key=isppoly(p)
|
||||
% isppoly - check whether input is an ppoly object
|
||||
%
|
||||
% key=isppoly(p)
|
||||
%
|
||||
% key returns 1 or 0
|
||||
|
||||
% Copyright (c) Dingyu Xue, Northeastern University, China
|
||||
% Last modified 18 May, 2022
|
||||
key=strcmp(class(p),'ppoly');
|
||||
end
|
12
FOTF Toolbox/@ppoly/latex.m
Normal file
12
FOTF Toolbox/@ppoly/latex.m
Normal file
@ -0,0 +1,12 @@
|
||||
function strA=latex(p)
|
||||
% latex - convert ppoly object into LaTeX string
|
||||
%
|
||||
% str=latex(p)
|
||||
%
|
||||
% p - a ppoly object
|
||||
|
||||
% Copyright (c) Dingyu Xue, Northeastern University, China
|
||||
% Last modified 18 May, 2022
|
||||
str=disp(p); str=strrep(str,'*s','s');
|
||||
if nargout==0, disp(str), else, strA=str; end
|
||||
end
|
11
FOTF Toolbox/@ppoly/minus.m
Normal file
11
FOTF Toolbox/@ppoly/minus.m
Normal file
@ -0,0 +1,11 @@
|
||||
function p=minus(p1,p2)
|
||||
% minus - find the differences in two ppoly objects
|
||||
%
|
||||
% p=p1-p2
|
||||
%
|
||||
% p, p1, p2 - ppoly objects
|
||||
|
||||
% Copyright (c) Dingyu Xue, Northeastern University, China
|
||||
% Last modified 18 May, 2022
|
||||
p=p1+(-p2);
|
||||
end
|
15
FOTF Toolbox/@ppoly/mpower.m
Normal file
15
FOTF Toolbox/@ppoly/mpower.m
Normal file
@ -0,0 +1,15 @@
|
||||
function p1=mpower(p,n)
|
||||
% mpower - power of a ppoly object
|
||||
%
|
||||
% p1=p^n
|
||||
%
|
||||
% p - a ppoly object
|
||||
|
||||
% Copyright (c) Dingyu Xue, Northeastern University, China
|
||||
% Last modified 18 May, 2022
|
||||
if length(p.a)==1, p1=ppoly(p.a^n,p.na*n);
|
||||
elseif n==floor(n)
|
||||
if n<0, p.na=-p.na; n=-n; end
|
||||
p1=ppoly(1); for i=1:n, p1=p1*p; end
|
||||
else, error('n must be an integer'), end
|
||||
end
|
11
FOTF Toolbox/@ppoly/mrdivide.m
Normal file
11
FOTF Toolbox/@ppoly/mrdivide.m
Normal file
@ -0,0 +1,11 @@
|
||||
function p=mrdivide(p1,p2)
|
||||
% mrdivide - right divide ppoly objects
|
||||
%
|
||||
% p=p1/p2
|
||||
%
|
||||
% p, p1, p2 - ppoly objects
|
||||
|
||||
% Copyright (c) Dingyu Xue, Northeastern University, China
|
||||
% Last modified 18 May, 2022
|
||||
p1=collect(ppoly(p1)); p2=collect(ppoly(p2)); p=fotf(p2,p1);
|
||||
end
|
12
FOTF Toolbox/@ppoly/mtimes.m
Normal file
12
FOTF Toolbox/@ppoly/mtimes.m
Normal file
@ -0,0 +1,12 @@
|
||||
function p=mtimes(p1,p2)
|
||||
% mtimes - product of two ppoly objects
|
||||
%
|
||||
% p=p1*p2
|
||||
%
|
||||
% p, p1, p2 - ppoly object
|
||||
|
||||
% Copyright (c) Dingyu Xue, Northeastern University, China
|
||||
% Last modified 18 May, 2022
|
||||
p1=ppoly(p1); p2=ppoly(p2); a=kron(p1.a,p2.a);
|
||||
na=kronsum(p1.na,p2.na); p=collect(ppoly(a,na));
|
||||
end
|
12
FOTF Toolbox/@ppoly/plus.m
Normal file
12
FOTF Toolbox/@ppoly/plus.m
Normal file
@ -0,0 +1,12 @@
|
||||
function p=plus(p1,p2)
|
||||
% plus - sum of twp ppoly objects
|
||||
%
|
||||
% p=p1+p2
|
||||
%
|
||||
% p, p1, p2 - ppoly objects
|
||||
|
||||
% Copyright (c) Dingyu Xue, Northeastern University, China
|
||||
% Last modified 18 May, 2022
|
||||
p1=ppoly(p1); p2=ppoly(p2);
|
||||
a=[p1.a,p2.a]; na=[p1.na,p2.na]; p=collect(ppoly(a,na));
|
||||
end
|
15
FOTF Toolbox/@ppoly/ppoly.m
Normal file
15
FOTF Toolbox/@ppoly/ppoly.m
Normal file
@ -0,0 +1,15 @@
|
||||
% ppoly - class definition of a ppoly object
|
||||
|
||||
% Copyright (c) Dingyu Xue, Northeastern University, China
|
||||
% Last modified 18 May, 2022
|
||||
classdef ppoly
|
||||
properties, a, na, end
|
||||
methods
|
||||
function p=ppoly(a,na)
|
||||
if nargin==1
|
||||
if isa(a,'double'), p=ppoly(a,length(a)-1:-1:0);
|
||||
elseif isa(a,'ppoly'), p=a;
|
||||
elseif a=='s', p=ppoly(1,1); end
|
||||
elseif length(a)==length(na), p.a=a; p.na=na;
|
||||
else, error('Error: miss matching in a and na'); end
|
||||
end, end, end
|
11
FOTF Toolbox/@ppoly/uminus.m
Normal file
11
FOTF Toolbox/@ppoly/uminus.m
Normal file
@ -0,0 +1,11 @@
|
||||
function p1=uminus(p)
|
||||
% uminus - find -p
|
||||
%
|
||||
% p1=-p
|
||||
%
|
||||
% p, p1 - ppoly objects
|
||||
|
||||
% Copyright (c) Dingyu Xue, Northeastern University, China
|
||||
% Last modified 18 May, 2022
|
||||
p1=ppoly(-p.a,p.na);
|
||||
end
|
Reference in New Issue
Block a user