Hello, I’m Hiroki🐶, a data scientist. In my previous blog, I introduced the Matlab code to solve the single degree of freedom vibration motion equation. I have modified it a bit more to represent it in terms of inputs and outputs, and I’d like to solve it this way.
![](OneDofModel.png)
First, this single degree of freedom vibration model. Normally, it can be written as a motion equation like this:
$$\begin{align*}
m\ddot{x}+c\dot{x}+kx&=f \
\end{align*}$$
Here,
$$\begin{align*}
f=c\dot{y}+ky& \
\end{align*}$$
The Matlab code to solve this model has been slightly modified from the previous code and is as follows:
% Definition of parameters
m = 1; % Mass [kg] ※Please set an appropriate value
k = 1; % Spring constant [N/m] ※Please set an appropriate value
c = 1; % Damping coefficient [N.s/m] ※Please set an appropriate value
% Definition of the differential equation
A = [0 1; -k/m -c/m];
B = [0; 1/m];
C = [1 0];
D = 0;
% Creation of the state space model
sys = ss(A, B, C, D);
% Simulation of the response
t = linspace(0, 50, 1000); % Simulation time [s]
% Applying external force f to the system
Y=1;
w0=sqrt(k/m);
f = c*Y*w0*cos(w0*t)+k*Y * sin(w0*t); % Time series of the external force
y = lsim(sys, f, t);
% Plotting the results
figure;
plot(t, y);
xlabel('Time [s]');
ylabel('Displacement [m]');
title('Response of the physical model');
grid on;
Upon execution, you might have obtained a graph like the one below.
![](graph.png)
This shows how easily and systematically you can determine the output x when inputting f into an M K C system.
In the following posts, I plan to apply this to more complex systems.
That’s it for today.
Thank you for reading until the end.
Love & Respect♡
Hiroki🐶