My code won't run, error message :Unrecognized function or variable 'ss'. Error in Q4_109 (line 19) Sys=ss(A,B,C,D);
Ältere Kommentare anzeigen
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)

Antworten (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 Kommentare
Abuqasem
am 30 Jun. 2022
Star Strider
am 30 Jun. 2022
My pleasure!
If my Answer helped you solve your problem, please Accept it!
.
the cyclist
am 30 Jun. 2022
1 Stimme
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.
1 Kommentar
Abuqasem
am 30 Jun. 2022
Kategorien
Mehr zu MATLAB finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

