Error while multiplying 2 SISO transfer functions.

I have a script that reads transfer functions from .mat files, and I have what it looks like to be tf([-0.5 0],[0 1]) (I will note this with C1) and tf([0 1],[0.5 1]) (I will note this with C2). When I do the operation C1 * C2, I get the error:
"Error using *
First argument must be single or double."
I have also tried series(C1,C2), but I get the same error. (Both of them are tf type variables.)
Why I can not multiply those 2 transfer functions? Since I can not include my code (because I use multiple classes and the reader would need a repository to understand what those classes do) I am satisfied with theoretical scenarios regarding the nature of the error like "the number of inputs of C1 is not the same as the number of outputs of C2" (but this is not the case, since both are SISO tf).
Edit: tf is not overriden and it is the same tf as Transfer function model - MATLAB (mathworks.com).
Edit 2: I have tried with some other tf for C2, and I have found that if C2 is a static gain, the multiplication is done without any issue. But if C2 has numerator or/ and denominator a polynom with 2 or more coefficients (dominant coefficient non zero), the "First argument must be single or double" error is displayed.

댓글 수: 11

No issue if run manually here. Maybe something wrong when passing the data type in your transfer functions.
G1 = tf([-0.5 0],[0 1])
G1 = -0.5 s Continuous-time transfer function.
G2 = tf([0 1], [0.5 1])
G2 = 1 --------- 0.5 s + 1 Continuous-time transfer function.
% method 1
G1*G2
ans = -0.5 s --------- 0.5 s + 1 Continuous-time transfer function.
% method 2
series(G1, G2)
ans = -0.5 s --------- 0.5 s + 1 Continuous-time transfer function.
Bogdan -Ervin
Bogdan -Ervin 2024년 4월 24일
편집: Bogdan -Ervin 2024년 4월 24일
By writing manually I can multiply them too, but in the script they (the 2 read tfs) can not be multiplied.
I have tried with some other tf for C2, and I have found that if C2's numerator is a static gain, the multiplication is done without any issue. But if C2 has numerator or/ and denominator a polynom with 2 or more coefficients (dominant coefficient non zero), the above error is displayed.
Does the script have symbolic variables and values? Can you check the class and data type?
It has, but no symbolic variable or assumption is created when the 2 tf are multiplied.
Bogdan -Ervin
Bogdan -Ervin 2024년 4월 25일
편집: Bogdan -Ervin 2024년 4월 25일
Also C1 and C2 are tf (this is what class(C1) and class(C2) says).
I have also compared C1 with "C1 declared from Command Window", and the content of both are identical, even their InputGroup, OutputGroup, Notes and SamplingGrid are the same (empty).
If I multiply the "C1 declared from command window" to C2, the 2 tf are multiplied without any issue. But C1 (the one read in script) can not be multiplied with C2.
The error message indicates that the first input argument to the multiplication operator (*) should be of class single or double. However, it is important to note that the 'tf' class object represents a dynamic model, which logically should accept any type of linear time-invariant model (such as ss, tf, zpk) in this context.
I would suggest checking if the 'C1' variable, which represents the transfer function in the script, has been inadvertently overwritten by another object of different class.
Bogdan -Ervin
Bogdan -Ervin 2024년 4월 25일
편집: Bogdan -Ervin 2024년 4월 25일
I have tried to debug in Matlab R2021b, since in that version is it told at which function and line (more or less the root of it) the error happened.
The error happens in ltipack package (I use Matlab R2021b terminology), ltidata class, mtimesDelay method at line 32, where norm(Dm12,1) throws an error, because Dm12 is a vector (of only 2 elements) and has the data type int16 instead of single or double.
The error happens in the same place in Matlab R2023b.
2 strange things happens:
  1. C1 and C2 from script, D1.Delay.IO and D2.Delay.IO (from line 25 and 26 for example) will be of int16 datatype. C1 and C2 from command window have D1.Delay.IO and D2.Delay.IO both of type double.
  2. With C1 and C2 from script, Dm1 and Dm2 (lines 25 and 26) will have different data types. Dm1 will be int16, and Dm2 will be double, thus Dm12 (line 28) will be of type int16. I do not understand why Dm1 is int16, but Dm2 is double, since both D1.Delay.IO and D2.Delay.IO are int16, but both repmat(D1.Delay.Input.',[ny 1]) and repmat(D2.Delay.Output,[1 nu]) are of type double.
Still I do not understand how should I modify my code. On one hand, I can do some verifications on C1.Data_ and C2.Data_ (like in lines 649 from tf.m), but I am lost in how Data_ is even created, and tf does not derive from dynamicprops.
Try saving the C1 and C2 variables (produced by the script) from Workspace to a mat-file.
save dataC1C2.mat
Then upload/attach the mat-file here by clicking the paperclip icon .
This is for recreating the error message "First argument must be single or double." Although C1 is an improper transfer function, it cannot even produce the Bode diagram.
load('dataC1C2.mat')
disp(C1)
tf with properties: Numerator: {[-0.5000 0]} Denominator: {[0 1]} Variable: 's' IODelay: [0] InputDelay: [0] OutputDelay: [0] InputName: {''} InputUnit: {''} InputGroup: [1x1 struct] OutputName: {''} OutputUnit: {''} OutputGroup: [1x1 struct] Notes: [0x1 string] UserData: [] Name: '' Ts: [0] TimeUnit: 'seconds' SamplingGrid: [1x1 struct]
disp(C2)
tf with properties: Numerator: {[0 1]} Denominator: {[0.5000 1]} Variable: 's' IODelay: [0] InputDelay: [0] OutputDelay: [0] InputName: {''} InputUnit: {''} InputGroup: [1x1 struct] OutputName: {''} OutputUnit: {''} OutputGroup: [1x1 struct] Notes: [0x1 string] UserData: [] Name: '' Ts: [0] TimeUnit: 'seconds' SamplingGrid: [1x1 struct]
bode(C1), grid on
Warning: Error occurred while evaluating listener callback.
bode(C2), grid on
C1*C2
Error using * (line 77)
First argument must be single or double.

댓글을 달려면 로그인하십시오.

 채택된 답변

Sam Chak
Sam Chak 2024년 4월 25일
load('dataC1C2.mat')
While I haven't been able to pinpoint the exact root cause of the issue, I can suggest a workaround below that you can try.
Simply add the following line of code to your script, right after the generation of the old C1 transfer function. This addition should help create a new C1 transfer function and hopefully eliminate the error you encountered.
Please give it a try and let me know if it resolves the problem.
%% Add this line:
C1 = tf(C1.Numerator{:}, C1.Denominator{:})
C1 = -0.5 s Continuous-time transfer function.
C1*C2
ans = -0.5 s --------- 0.5 s + 1 Continuous-time transfer function.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Dynamic System Models에 대해 자세히 알아보기

제품

릴리스

R2023b

질문:

2024년 4월 24일

답변:

2024년 4월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by