Topic: Position, Velocity & Acceleration Plot as a Function of Time
Subject: Numerical Methods & Kinematics
Tool: Scilab
In the subject of kinematics, the position, velocity, and acceleration as a function of time can be plotted using the forward difference of the numerical method of differentiation. For a given position as a function of time, t, as represented by s = f(t), velocity and acceleration can be solved as s' = f'(t) and s'' = f''(t), respectively.
The Scilab "diff()" function facilitates the numerical differentiation of a given function.
Below is an example of a Scilab script to make a plot of position, velocity, and acceleration as a function of time.
Scilab Script.
// Copyright (C) 2024 - Gani Comia
// Date of creation: 21 Nov. 2024
// Position, Velocity & Acceleration as a function of time
clear;clc;
// Given: Position as a function of time, t.
// s(t)=3t^4 - 35t^3 + 120t^2 - 10
function s=f(t)
s = 3*t.^4 - 35*t.^3 + 120*t.^2 - 10
endfunction
dt = 0.01 // time step, dt
t = 0:dt:5 // time range, t
s = f(t) // position, s
v = diff(s)/dt // velocity, ds/dt (s')
a = diff(s,2)/dt.^2 // acceleration, d2s/dt2 (s'')
clf;
f = gcf()
f.figure_size = [600,700]
// position vs time plot
subplot(3,1,1)
plot(t,s,"-r","linewidth",2.5)
title_1=["Position ,", "$s=3\;t^4-35\;t^3+120\;t^2-10$"]
title(title_1, "fontsize",3)
ylabel("position, s")
xgrid()
// velocity vs time plot
subplot(3,1,2)
plot(t(1:$-1),v,"-b","linewidth",2.5)
title_2=["Velocity ,", "${ds}\;/\;{dt}$"]
title(title_2,"fontsize",3)
ylabel("velocity, v")
xgrid()
// acceleration vs time plot
subplot(3,1,3)
plot(t(1:$-2),a,"-g","linewidth",2.5)
title_3=["Acceleration ,", "${d^2s}\;/\;{dt^2}$"]
title(title_3,"fontsize",3)
ylabel("acceleration, a")
xlabel("time, t","fontsize",2)
xgrid()
Below is the graph as a result of running the Scilab script.
Fig. 1. Graph of Position, Velocity & Acceleration as a function of Time.
Feel free to comment for inquiry, clarification, or suggestion for improvement. Drop your email to request the soft copy of the file.
Disclaimer: The formulas and calculations presented are for technical reference only. Users must verify the accuracy and ensure compliance with applicable engineering standards, codes, and safety requirements before practical application.
No comments:
Post a Comment