Semi-implicit Euler vs Transfer Function (Spring Mass Damper Simulation)
This experiment simulates the response of a first-order dynamic system approaching a desired speed. Using Forward Euler integration, I investigated how the time constant affects response speed and how discrete time steps approximate continuous-time behavior.
Model a second-order mechanical system and compare its position response using Semi-Implicit Euler integration and a transfer-function model under identical physical conditions.
I ran two simulations with identical initial conditions but using different computation methods.
Semi-Implicit Euler
I implemented a numerical simulation based on Newton's Second Law:
a = u - bv - kp/m
At each time step, the simulation calculates acceleration, updates velocity, and then uses the updated velocity to calculate the new position.
a = (u - b*v - k*p)/m;
v = v + a*dt;
p = p + v*dt;
Transfer Function
I separately modeled the same system using its transfer function:
G(s) = X(s)/F(s) = 1/(ms^2 + bs + k)
MATLAB's tf() function creates the continuous-time model, while step() calculates its position response at the requested time points.
The implementation uses three MATLAB files:
euler_sim.m: Calculates position using Semi-Implicit Euler integration.
tf_model.m: Generates the continuous-time transfer-function response.
compare_models.m: Plots both responses and calculates their absolute position differences.
Both models were simulated using identical physical parameters and initial conditions. The simulation duration was determined using the approximate 2% settling-time equation for an underdamped second-order system using T = 4/(damping ratio* natural frequency).
Applied force: 1 N
Mass: 2 kg
Damping coefficient: 0.4 N·s/m
Spring constant: 0.4 N/m
Initial position and velocity: 0
Numerical time step: 0.02 s
Equilibrium position: 2.5 m
Position Response Comparison
Both methods produced nearly identical underdamped responses. The mass initially accelerated under the applied force, overshot its equilibrium position of 2.5 m, and oscillated around it with decreasing amplitude due to damping.
Numerical Error Comparison
Although the position curves closely overlapped, the absolute error plot revealed small differences between the two predictions.
The maximum recorded absolute position difference was approximately 0.01054 m (10.54 mm).
These differences arise because Semi-Implicit Euler approximates motion through discrete time steps, while the transfer-function model represents the continuous-time system.
This experiment demonstrated that the same dynamic system can be modeled using different mathematical approaches while producing closely matching results. I gained a better understanding of how damping causes oscillations to decay and how numerical integration introduces approximation errors, even when two response curves appear nearly identical.
Next experiment will be about system stability and poles.