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

My pleasure!
If my Answer helped you solve your problem, please Accept it!
.

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

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에 대해 자세히 알아보기

질문:

2022년 6월 30일

댓글:

2022년 6월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by