My code won't run, error message :Unrecognized function or variable 'ss'. Error in Q4_109 (line 19) Sys=ss(A,B,C,D);
古いコメントを表示
clear;clc
close all
M=[4 0 0 0;0 3 0 0;0 0 2.5 0;0 0 0 6];
C=[4 -1 0 0 ;-1 2 -1 0;0 -1 2 -1;0 0 -1 1];
K=[500 -100 0 0;-100 200 -100 0;0 -100 200 -100;0 0 -100 100];
x0=[0;0;0;0.01];
v0=[1;0;0;0];
B=[0;0;0;0;0;0;0;1];
t=0:0.01:80;
u=sin(4*t);
A=[zeros(4,4) eye(4);-inv(M)*K -inv(M)*C];
X0=[x0;v0];
C=[eye(4) zeros(4,4)];D=[0;0;0;0];
Sys=ss(A,B,C,D);
[x,tout,X]=lsim(Sys,u,t,X0);
plot(tout,x(:,1),tout,x(:,2),tout,x(:,3),tout,x(:,4))
xlabel('Time');ylabel('x')
legend('x_1','x_2','x_3','x_4')
I'm trying to code and plot this... (see attached)

回答 (2 件)
If you are getting an error that MATLAB cannot find the ss function, then you need to license and install the Control System Toolbox.
The code otherwise works as written —
M=[4 0 0 0;0 3 0 0;0 0 2.5 0;0 0 0 6];
C=[4 -1 0 0 ;-1 2 -1 0;0 -1 2 -1;0 0 -1 1];
K=[500 -100 0 0;-100 200 -100 0;0 -100 200 -100;0 0 -100 100];
x0=[0;0;0;0.01];
v0=[1;0;0;0];
B=[0;0;0;0;0;0;0;1];
t=0:0.01:80;
u=sin(4*t);
A=[zeros(4,4) eye(4);-inv(M)*K -inv(M)*C];
X0=[x0;v0];
C=[eye(4) zeros(4,4)];D=[0;0;0;0];
Sys=ss(A,B,C,D);
[x,tout,X]=lsim(Sys,u,t,X0);
plot(tout,x(:,1),tout,x(:,2),tout,x(:,3),tout,x(:,4))
xlabel('Time');ylabel('x')
legend('x_1','x_2','x_3','x_4')
.
2 件のコメント
Abuqasem
2022 年 6 月 30 日
Star Strider
2022 年 6 月 30 日
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
the cyclist
2022 年 6 月 30 日
1 投票
As you can see, I was able to run your code here.
I expect you do not have the ss function, which is in the Control System Toolbox. You need to have that toolbox installed.
カテゴリ
ヘルプ センター および File Exchange で MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

