Why does my discrete transfer function block cause a Simulink "domain error"?
8 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2018-2-23
回答: MathWorks Support Team
2018-2-28
I have a model with a continuous transfer function block. Since I want to generate code from this model, I have changed this continuous transfer function block to a discrete transfer function block that uses the same coefficients as my continuous transfer function block. Now, even if I just simulate the model, I get this error saying "to compute complex results from real x, use 'sqrt(complex(x))'.
How can I avoid this error when using a discrete transfer function?
采纳的回答
MathWorks Support Team
2018-2-23
This error can be resolved by converting the coefficients for the discrete transfer function. A continuous and a discrete transfer function with the same coefficients can have different outputs. In this case, the outputs of the discrete transfer function with the continuous coefficients were negative and unstable, causing this error.
To find the equivalent discrete coefficients, start with a continuous S-domain transfer function - for example, 1/(Ls+R). Then, use the "c2d" function to convert this into a discrete transfer function. The "c2d" function requires a sample time input. For this model, the desired sample time was 0.0001.
>> TFc = tf(1,[L R]);
>> TFd = c2d(TFc, 0.0001, 'matched');
Enter the coefficients from "TFd" into your discrete transfer function block, and the error will be resolved.
Note that the "c2d" function is not supported for code generation, so this conversion will have to take place outside the simulation.
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!