why is the zpk function not producing the transfer function in MATLAB?
조회 수: 10 (최근 30일)
이전 댓글 표시
Hello guys,
I am trying to use the zpk function, where I input the zeros, poles and gain and it should return the factored form of the transfer function but it is not giving me that output. The code I used is below with the output I am getting from zpk.
a = [2,5,9,5,3];
b = [5,45,2,1,1];
[zer,pol,t] = zplane(a,b);
z = zeros(1,4);
p = zeros(1,4);
%disp('Zeros of the Transfer function are: ');
for i = 1:4
X = ['(',num2str(zer.XData(i)),',',num2str(zer.YData(i)),')'];
z(i) = zer.XData(i) + 1i*zer.YData(i);
%disp(X)
end
%disp('Poles of the transfer function are: ');
for i = 1:(length(b)-1)
X = ['(',num2str(pol.XData(i)),',',num2str(pol.YData(i)),')'];
p(i) = pol.XData(i) + 1i*pol.YData(i);
%disp(X);
end
%disp(z);
G = zpk([z],[p],1);
disp(G);
Output:
zpk with properties:
Z: {[4×1 double]}
P: {[4×1 double]}
K: 1
DisplayFormat: 'roots'
Variable: 's'
IODelay: 0
InputDelay: 0
OutputDelay: 0
Ts: 0
TimeUnit: 'seconds'
InputName: {''}
InputUnit: {''}
InputGroup: [1×1 struct]
OutputName: {''}
OutputUnit: {''}
OutputGroup: [1×1 struct]
Notes: [0×1 string]
UserData: []
Name: ''
SamplingGrid: [1×1 struct]
댓글 수: 0
채택된 답변
Star Strider
2022년 2월 11일
Remove the closing parentheses in the ‘G’ assignment to see the result as a sort of ‘prettyprint’ output:
a = [2,5,9,5,3];
b = [5,45,2,1,1];
[zer,pol,t] = zplane(a,b);
z = zeros(1,4);
p = zeros(1,4);
%disp('Zeros of the Transfer function are: ');
for i = 1:4
X = ['(',num2str(zer.XData(i)),',',num2str(zer.YData(i)),')'];
z(i) = zer.XData(i) + 1i*zer.YData(i);
%disp(X)
end
%disp('Poles of the transfer function are: ');
for i = 1:(length(b)-1)
X = ['(',num2str(pol.XData(i)),',',num2str(pol.YData(i)),')'];
p(i) = pol.XData(i) + 1i*pol.YData(i);
%disp(X);
end
%disp(z);
G = zpk([z],[p],1)
Zv = G.Z{:}
Pv = G.P{:}
Kv = G.K
disp(G)
.
댓글 수: 6
Star Strider
2022년 2월 12일
As always, my pleasure!
It might be possible to add that as a format option for the ‘prettyprint’ output. The best way to approach that is to Contact Support and request that as an enhancement.
추가 답변 (1개)
Paul
2022년 2월 11일
What output is expected? It looks like zpk() is returning a zpk object with poles and zeros at locations shown on the plot.
a = [2,5,9,5,3];
b = [5,45,2,1,1];
[zer,pol,t] = zplane(a,b);
z = zeros(1,4);
p = zeros(1,4);
%disp('Zeros of the Transfer function are: ');
for i = 1:4
X = ['(',num2str(zer.XData(i)),',',num2str(zer.YData(i)),')'];
z(i) = zer.XData(i) + 1i*zer.YData(i);
%disp(X)
end
%disp('Poles of the transfer function are: ');
for i = 1:(length(b)-1)
X = ['(',num2str(pol.XData(i)),',',num2str(pol.YData(i)),')'];
p(i) = pol.XData(i) + 1i*pol.YData(i);
%disp(X);
end
%disp(z);
G = zpk([z],[p],1);
G
G.Z{:}
G.P{:}
The order of the inputs to zplane are zplane(numerator,denominator). Is a really the numerator and b really the denominator? Only asking because the typical naming convention in Matlab is that b is the numerator and a is the denominator. Will continue assuing a is the num and b is the den, but I suggest rechecking that.
If the goal is just to get the zpk representation with poles and zeros governed by a and b with a gain of k=1, that code seems like a really complicated way to go about it. Could just do
G1 = zpk(roots(a),roots(b),1)
However, if the goal is get the zpk representation of the transfer function a(s)/b(s), then there is an error because the gain is not unity
G2 = zpk(tf(a,b))
Note the gain k = 0.4.
Finally, the code is uzing zplane which suggests these are poles and zeros of a discrete time transfer function. As can be seen, zpk returns a continuous time model unless the sample time argument is provided.
G3 = zpk(tf(a,b,-1))
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

