How to prevent rounding number

23 次查看(过去 30 天)
Hello everyone, I have a trouble about rounding. This is my example: I assign K=173.1227 but the numerator the transfer function G is 173.1. When I try K=173.227, the num of G is 173.2. How can I fix that? I try to format long and go to preferences to adjust the variable and command windows but that doesn't work. Please help me! TIA

采纳的回答

Walter Roberson
Walter Roberson 2023-5-16
G1 = tf(173.1227, conv([1 0.2], [1 8 20]))
G1 = 173.1 -------------------------- s^3 + 8.2 s^2 + 21.6 s + 4 Continuous-time transfer function.
format long g
G1.numer
ans = 1×1 cell array
{[0 0 0 173.1227]}
The transfer function itself is not using the rounded values. The rounded values are only for display purposes.
The internal code does not offer any way to configure the number of significant digits: it always uses %.4g format for non-integers.
  2 个评论
Hoang Le Tran
Hoang Le Tran 2023-5-16
Can I ask you a question about K? I use the command Margin to find the k neutral limitation. And I assign the K into the transfer function to test is the K right?.
G=tf([1],conv([1 0.2],[1 8 20]))
G = 1 -------------------------- s^3 + 8.2 s^2 + 21.6 s + 4 Continuous-time transfer function.
K=margin(G)
K = 173.1227
But unfortunately, it is not right 100%. Can you help me?
Walter Roberson
Walter Roberson 2023-5-16
Sorry, I am not familiar with margin or "k neutral limitation"
format long g
G=tf([1],conv([1 0.2],[1 8 20]))
G = 1 -------------------------- s^3 + 8.2 s^2 + 21.6 s + 4 Continuous-time transfer function.
K = margin(G)
K =
173.122670692379

请先登录,再进行评论。

更多回答(1 个)

FannoFlow
FannoFlow 2023-5-16
Your data is still there, its just not printing out the full precision.
See also:
K2 = 173.227;
K2 = 173.2270
G2 = tf([K2, conv(1, 0.2)], [1, 8, 20])
G2 = 173.2 s + 0.2 -------------- s^2 + 8 s + 20 Continuous-time transfer function.
G2.numerator
ans = 1×1 cell array
{[0 173.2270 0.2000]}
G2.denominator
ans = 1×1 cell array
{[1 8 20]}
  2 个评论
Hoang Le Tran
Hoang Le Tran 2023-5-16
移动:Walter Roberson 2023-5-16
Thank you very much @Walter Roberson @FannoFlow. Perhaps, the value of k neutral limitation in transfer function is not exactly.
Walter Roberson
Walter Roberson 2023-5-16
The calculations for the transfer function use the full precision of the values you use to construct the transfer function (or state space system)
Only the display of the transfer function is affected.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by