Index exceeds array bounds; transfer function model.

2 ビュー (過去 30 日間)
an Electrical Engineering Student
an Electrical Engineering Student 2021 年 4 月 13 日
コメント済み: Sam Chak 2025 年 4 月 3 日
I'm modelling the dynamics of an inverted pendulum system. Here's my code:
m=0.1283; M=0.5; I=0.0107; g=9.81; L=0.5;
s=tf('s')
s = s Continuous-time transfer function.
J=m*(L^2)/4+I;
H=M+m;
G=m*g*L/2;
E=m*L/2;
P=J*H-E^2;
format short
sys=1/(P/E*s^2-(E^2+P)*G/(J*E))
sys = 1 ------------------ 0.3346 s^2 - 6.164 Continuous-time transfer function.
Which [produced the expected result here, but] yields the following error [in my computer]:
Index exceeds array bounds.
Error in sym/subsref (line 859)
R_tilde = builtin('subsref',L_tilde,Idx);
Error in modelo_dominio_s_sin_friccion (line 5)
s=tf('s')
How can I fix it? I'm not sure why there appears to be an error with s=tf('s') when it appears exactly like that in the 'tf' documentation.
  3 件のコメント
Walter Roberson
Walter Roberson 2025 年 4 月 3 日
Indeed, this error is due to having an existing variable named tf
Sam Chak
Sam Chak 2025 年 4 月 3 日
Let's test out @Walter Roberson's hypothesis...
%% ----- assign an existing variable named 'tf' -----
tf = 2; % Test 1
% syms tf % Test 2
% tf = @(x) 2*x; % Test 3
% --------------------------------------------------
m=0.1283; M=0.5; I=0.0107; g=9.81; L=0.5;
s=tf('s')
Index exceeds the number of array elements. Index must not exceed 1.

tf appears to be both a function and a variable. If this is unintentional, use 'clear tf' to remove the variable 'tf' from the workspace.
J=m*(L^2)/4+I;
H=M+m;
G=m*g*L/2;
E=m*L/2;
P=J*H-E^2;
format short
sys=1/(P/E*s^2-(E^2+P)*G/(J*E))

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by