Saturday, 4 January 2025

Free-Falling Body under Gravitational Field

Topic: Gravitational Interaction

Subject: Physics

Tool: Scilab

by:  Gani Comia, Jan. 2025

A free-falling body or object falls to the ground under the sole influence of gravity. Air resistance or any form of propulsion that acted on the object are not considered in this concept. The ordinary differential equation (ODE) in equation (1) helps explain the motion of objects in a gravitational field. The acceleration due to gravity, denoted by “\(g\)”, is approximately equal to \(\text{9.8}\;m/s^2\) on the surface of the Earth.

$$\frac{d^2 y}{dt^2}\;=\;-\;g \tag{1}$$

Solution to the given 2nd-order ODE will be based on the initial conditions as shown in equation (2).

$$\left(\;t_0 = t,\;y_0 = y,\;\frac{dy}{dt}(t_0) = v \right) \tag{2}$$

The 2nd-order ODE needs to be transformed in the system of 1st-order ODE before using it to the Scilab’s \(ode()\) function. Figure 1 which shows the position and velocity over time domain is the solution to the ODE. Instantaneous position and velocity at t = 60 sec are plotted on the graph as an example.

Figure 1. Solution to 2nd – order ODE representing Free-Falling Body.

Scilab's Script:

The first block on the script is the re-written 2nd-order ODE in the system of 1st-order ODE’s.

clear;clc;
// y'' = -g                 2nd-order ODE model for free-falling body
// y(0) = 0                 initial position
// y'(0) = 0                initial velocity

// (1) system of 1st-order ODEs equivalent to 2nd-order ODE
function dydt=freeFall(t, y)
    g = 9.8;                // m/s^2, gravitational acceleration
    dydt(1) = y(2);         // dy/dt = v
    dydt(2) = -g;           // dv/dt = -g
endfunction

Time domain considered for this solution is from 0 to 120 seconds and the initial conditions are shown in equation (3).

$$\left(\;t_0 = 0,\;y_0 = 0,\;\frac{dy}{dt}(0) = 0 \right) \tag{3}$$

Its Scilab script is shown below.

// (2) time domain and initial conditions
t = 0:0.1:120;              // sec, time span
t0 = 0;                     // sec, initial time
y0 = [0; 0];                // initial position and velocity

Scilab’s \(ode()\) function is written on below script for the solution.

// (3) solution to ode
y = ode(y0, t0, t, freeFall)

The succeeding scripts are for Scilab plotting and calculation of the instantaneous position and velocity using interpolation. Solution vectors representing position and velocity are given in the variables \(y(1,:)\) and \(y(2,:)\) respectively. The function \(interp1()\) is used for interpolation at t = 60 sec.

// (4) plot size
clf;
f=gcf();
f.figure_size=[600,700];

// (5) time and displacement plot
subplot(2,1,1)
plot(t,y(1,:),"b-","linewidth",3)
title("$\large\text{Displacement, Free-Falling Body}$")
ylabel("Displacement [m]","fontsize",3)
legend(["$\LARGE {y}$"],with_box = %F)
xgrid(3,1)

// (6) time and velocity plot
subplot(2,1,2)
plot(t,y(2,:),"r-","linewidth",3)
title("$\large\text{Velocity, Free-Falling Body}$")
xlabel("Time [sec]","fontsize",3)
ylabel("Velocity [m/sec]","fontsize",3)
legend(["$\LARGE\frac{dy}{dt}$"],with_box = %F)
xgrid(3,1)
xstring(70,-400,["https://gani-mech-toolbox.blogspot.com"])

// (7) interpolating position, Yx, and its velocity, Vx
format(8)
tx = 60;                            // sec, sample time
Yx = interp1(t, y(1,:), tx);        // m, distance
Vx = interp1(t, y(2,:), tx);        // m/s^2, velocity
disp(tx, Yx, Vx)

// (8) plot of interpolated data, time and position
subplot(2,1,1)
vertLnXs = [tx tx]; vertLnYs = [0 Yx];
horLnXs = [0 tx]; horLnYs = [Yx Yx];
plot(vertLnXs, vertLnYs,"m--","linewidth",1.25)
plot(horLnXs, horLnYs,"m--","linewidth",1.25)
plot(tx,Yx,"mo")
xstring(tx+1,Yx,["y = "+string(Yx)+" m @ 60 sec"])
a = gca();
a.children.children.mark_background = 1;

// (9) plot of interpolated data, time and velocity
subplot(2,1,2)
vertLnXs = [tx tx]; vertLnYs = [0 Vx];
horLnXs = [0 tx]; horLnYs = [Vx Vx];
plot(vertLnXs, vertLnYs,"m--","linewidth",1.25)
plot(horLnXs, horLnYs,"m--","linewidth",1.25)
plot(tx,Vx,"mo")
xstring(tx+1,Vx,["dy/dt = "+string(Vx)+" m/sec @ 60 sec"])
a = gca();
a.children.children.mark_background = 1;
For the next article, introduction of air resistance to the ODE representing the free-falling body will be presented.

Feel free to comment for inquiry, clarification, or suggestion for improvement. Drop your email to request the soft copy of the file.

No comments:

Post a Comment

C++ and Python for Numerical Solution to Spring-Mass-Damper Model

Topic: SDOF Spring-Mass-Damper System Subject: Numerical Methods & Mechanical Vibration Tools: C++, CodeBlocks, GitHub Copilot, LabP...