ChatGPT x Programming of Physical Model

Programming Physical Modeling with ChatGPT

A must-see for a student in science! Expand your learning horizons with this super convenient way to use ChatGPT!

Hello, I’m Hiroki 🐶, a data scientist.
There’s been a lot of buzz recently about ChatGPT gaining new capabilities!
For example, check out this YouTube video.

I couldn’t wait to apply this!
For instance, a fundamental model taught in the first year of engineering studies is the single-degree-of-freedom vibration model.
It would be great to freely draw such a physical model and then perform numerical calculations on it.
ChatGPT makes this dream a reality!
So today, I will introduce:

  • How to program a single-degree-of-freedom vibration model using ChatGPT

Consider the following single-degree-of-freedom vibration model.

First, paste a screenshot of the above model into ChatGPT.
Then, type in, “Please teach me the Matlab code to solve this physical model.”

You will receive the following code:

% Definition of parameters
m = 1; % Mass [kg] ※Please set appropriate value
k = 1; % Spring constant [N/m] ※Please set appropriate value
c = 1; % Damping coefficient [N.s/m] ※Please set appropriate value
f = 1; % External force [N] ※Please set appropriate value or function

% 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, 10, 1000); % Simulation time [s]
u = f * ones(size(t)); % Time series of external force
y = lsim(sys, u, t);

% Plotting the results
figure;
plot(t, y);
xlabel('Time [s]');
ylabel('Displacement [m]');
title('Response of the physical model');
grid on;

Does it really work?

Tentatively, I copy-pasted it into Matlab and executed it, and……….

It worked!
To put it modestly, this is amazing!!!

I look forward to exploring this further ^^

That’s all for today.
Have a wonderful day^^
Love&Respect❤️
Hiroki🐶