Error in using lsim function
Mostrar comentarios más antiguos
I am trying to use the lsim function for my code but it is showing the error "Not enough input arguements". So, it would be great if anyone could help me regarding the same. Here's my code:
m = 250; m1 = m; m2 = m; % masses (all equal)
k = 50; k1 = k; k2 = k; k3 = k; % spring constants
c = 10; % damping
A = 0.00315; omega = 0.75; % forcing function
%
tspan=[0 500]; % time range for simulation
y0 = [0; 0; 0; 0]; % initial conditions
% Call ode45 routine
[t,y] = ode45(@springmass, tspan, y0, [], k1, k2, k3, m1, m2, c, A, omega);
%disp(y)
% Plot the input and outputs over entire period
figure(1); clf
plot(t, A*cos(omega*t), t, y(:,1), t, y(:,2));
%
%
N1 = [12500 500 5500 20 150];
D1 = [0 0 0 0 50];
%Gm1 = tf(D1,N1);
N2 = [1250 50 1000 20 1500];
D2 = [0 0 250 0 100];
%Gm2 = tf(D2,N2);
%bode(Gm1,Gm2);
%------------------------------------------------------
sys1 = tf2ss(D1,N1);
sys2 = tf2ss(D2,N2);
%u = A*cos(omega*t);
y1 = lsim(sys1, u, t);
figure(4);
plot(t,y1)
Here's my springmass function code:
function dydt = springmass(t, y, k1, k2, k3, m1, m2, c, A, omega)
% compute the input to drive the system
u = A*cos(omega*t);
% compute the time derivative of the state vector
dydt = [
y(3);
y(4);
-(k1+k2)/m1*y(1) + k2/m1*y(2);
k2/m2*y(1) - (k2+k3)/m2*y(2) - c/m2*y(4) + k3/m2*u
];
Here's the error which is popping up:
Error using lsim (line 88)
Not enough input arguments.
Error in main_HW1 (line 47)
y1 = lsim(sys1, u, t);
Any help would be greatly appreciated.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Programming en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

