Error using tf The values of the "Numerator" and "Denominator" properties must be row vectors or cell arrays of row vectors,
조회 수: 30 (최근 30일)
이전 댓글 표시
I am trying to find the poles and graph my result of a second order system but I am getting an error using tf. I've ensured that zeta and w_n are numerical values but I still get the error. Any help will be appreciated.
My Code:
clear
clc
close all
% Given
% rise time t_r <= 0.5sec
% percent overshoot M_p <= 13%
% settling time t_s <= 8sec
syms zeta theta w_n;
t_r = .5;
M_p = .13;
% Find zeta (Damping Factor)
eqn_1 = exp((-pi * zeta) / sqrt(1 - zeta^2)) == M_p;
zeta = vpasolve(eqn_1 , zeta)
% zeta >= values
% Find angle of roots lying on locus of zeta >= 0.545
eqn_2 = cosd(theta) == zeta;
theta = vpasolve(eqn_2 , theta) + 360
% Find w_n (Natural Freq)
eqn_3 = t_r == 1.8 / w_n;
w_n = vpasolve(eqn_3 , w_n)
% Ensure t_s <= given 8sec
t_s = 4 / (zeta * w_n)
% Calculate second order system
numerator = w_n^2;
denominator = [1 , (2 * zeta * w_n) , w_n^2];
% numerator = 3.6^2
% denominator = [1 , 3.92 , 3.6^2]
sys = tf(numerator , denominator)
pole(sys)
pzmap(sys)
Output:
zeta =
0.5446478046015929749424669699482
theta =
56.999400882750013102644103693468
w_n =
3.6
t_s =
2.0400543281798098625532390247806
Error using tf
The values of the "Numerator" and "Denominator" properties must be row
vectors or cell arrays of row vectors, where each vector is nonempty and
containing numeric data. Type "help tf.num" or "help tf.den" for more
information.
Error in ECE241_HW3_Num2 (line 35)
sys = tf(numerator , denominator)
>>
When I hard code the values into the transfer function it works as expected, but I'm wondering why it doesnt work with the variables
댓글 수: 0
채택된 답변
추가 답변 (1개)
Tushar Behera
2023년 2월 8일
편집: Tushar Behera
2023년 2월 8일
Hi Joe,
I belive the error is due to the fact that the variables "numerator" and "denominator" are symbolic variables.
this can be resolved by type casting them to double. However in order to keep the precison intact you should also use "vpa" function along with it. For example:
clear
clc
close all
% Given
% rise time t_r <= 0.5sec
% percent overshoot M_p <= 13%
% settling time t_s <= 8sec
syms zeta theta w_n;
t_r = .5;
M_p = .13;
% Find zeta (Damping Factor)
eqn_1 = exp((-pi * zeta) / sqrt(1 - zeta^2)) == M_p;
zeta = vpasolve(eqn_1 , zeta)
% zeta >= values
% Find angle of roots lying on locus of zeta >= 0.545
eqn_2 = cosd(theta) == zeta;
theta = vpasolve(eqn_2 , theta) + 360
% Find w_n (Natural Freq)
eqn_3 = t_r == 1.8 / w_n;
w_n = vpasolve(eqn_3 , w_n)
% Ensure t_s <= given 8sec
t_s = 4 / (zeta * w_n)
% Calculate second order system
numerator = double(vpa(w_n^2));
denominator = double(vpa([1 , (2 * zeta * w_n) , w_n^2]));
% numerator = 3.6^2
% denominator = [1 , 3.92 , 3.6^2]
sys = tf(numerator , denominator)
pole(sys)
pzmap(sys)
%%%
answer with hard coding
-1.9607 + 3.0192i
-1.9607 - 3.0192i
answer after using vpa
-1.9607 + 3.0192i
-1.9607 - 3.0192i
As you can observe the precision is not lost. to know more about "vpa" function you can refer,
Hope this solves your query.
Regards,
Tushar
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Numbers and Precision에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!