My code won't run, error message :Unrecognized function or variable 'ss'. Error in Q4_109 (line 19) Sys=ss(A,B,C,D);

12 visualizaciones (últimos 30 días)
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)

Respuestas (2)

Star Strider
Star Strider el 30 de Jun. de 2022
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')
.

the cyclist
the cyclist el 30 de Jun. de 2022
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.

Categorías

Más información sobre Power and Energy Systems en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by