Effacer les filtres
Effacer les filtres

Error using ^ for control systems related functions

2 vues (au cours des 30 derniers jours)
Mohammad Aliuddin Mohamed Anwer
Commenté : Sam Chak le 3 Oct 2023
I have a simple transfer function as shown below.
>> P = tf(8,[1 8])
P =
8
-----
s + 8
Continuous-time transfer function.
However when I attempt to use the minreal() function I encounter this error:
>> minreal(P)
Error using DynamicSystem/minreal
Incorrect dimensions for raising a matrix to a power. Check that the matrix is
square and the power is a scalar. To operate on each element of the matrix
individually, use POWER (.^) for elementwise power.
This error is not limited to the transfer function above but to more complex transfer functions as well. Additionally, I have encountered this issue when running other codes as well, notably converting state space models to a transfer function shown below.
>> A = [-1.5,-2;1,0];
B = [0.5;0];
C = [0,1];
D = 0;
sys = ss(A,B,C,D)
sys =
A =
x1 x2
x1 -1.5 -2
x2 1 0
B =
u1
x1 0.5
x2 0
C =
x1 x2
y1 0 1
D =
u1
y1 0
Continuous-time state-space model.
>> sys_as_tf = tf(sys)
Error using DynamicSystem/tf
Incorrect dimensions for raising a matrix to a power. Check that the matrix is
square and the power is a scalar. To operate on each element of the matrix
individually, use POWER (.^) for elementwise power.
Similarly when I attempt to convert a state space model to a transfer function using ss2tf I encounter the same error as well.
>> A = [-1.5,-2;1,0];
B = [0.5;0];
C = [0,1];
D = 0;
>> tfsys = ss2tf(A,B,C,D);
Error using ^
Incorrect dimensions for raising a matrix to a power. Check that the matrix is
square and the power is a scalar. To operate on each element of the matrix
individually, use POWER (.^) for elementwise power.
Error in poly (line 2)
sqrd=x^2+y;
Error in ss2tf (line 30)
den = poly(p);
I have tried reinstalling the toolbox, reinstalling MATLAB r2023a and even installed version r2022a but I am not able to resolve this error regardless of what I do. I assume it may have something to do with the laptop I am using as I do not face these issues on MATLAB Online but I am unsure of what specifically could be causing these issues locally in my device.

Réponse acceptée

Walter Roberson
Walter Roberson le 3 Oct 2023
you have supplied your own poly.m which is interfering with using the matlab poly() function
  2 commentaires
Mohammad Aliuddin Mohamed Anwer
Thank you, it worked! I forgot I created an m file long ago named poly.m and after deleting it everything worked.
Sam Chak
Sam Chak le 3 Oct 2023
@Mohammad Aliuddin Mohamed Anwer, Good to know that you fixed the issue. Thanks @Walter Roberson.

Connectez-vous pour commenter.

Plus de réponses (1)

Sam Chak
Sam Chak le 3 Oct 2023

Hi Aliuddin,

If you want to get the transfer function directly, then use this syntax:

tfsys = tf(ss(A,B,C,D))
  3 commentaires
Sam Chak
Sam Chak le 3 Oct 2023

Try fixing this one:

sqrd = x.^2 + y
Mohammad Aliuddin Mohamed Anwer
I assume you mean I should edit my poly() function to the add in the element-wise exponential? I tried doing that and I end up having a different error indicating I have insufficient input arguments.
>> tfsys = tf(ss(A,B,C,D))
Error using DynamicSystem/tf
Not enough input arguments.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Get Started with Control System Toolbox dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by