velocity
average and instantaneous velocity of an object
Interface
#include <codecogs/physics/kinematics/velocity.h>
using namespace Physics::Kinematics;
Overview
This module computes the average and instantaneous velocity of a moving object at given moments of time.
FUNCTION
velocity_avg
This function computes the average velocity of a moving object, given its initial and final position on an axis and also the total time spent to get to that final position. Considering is the initial position at time
and
is the final position at time
, the average velocity
is given by the following simple formula:
Example 1
#include <codecogs/physics/kinematics/velocity.h>
#include <iostream>
int main()
{
// final position and time
double x = 100, t = 15.7;
std::cout << std::endl;
std::cout << " Final position = " << x << " m" << std::endl;
std::cout << " Time spent = " << t << " s" << std::endl;
std::cout << std::endl;
// assuming initial position and initial time are null,
// display the average velocity of the object
std::cout << "Average velocity = " <<
Physics::Kinematics::velocity_avg(x, t);
std::cout << " m/s" << std::endl;
return 0;
}Output
Final position = 100 m
Time spent = 15.7 s
Average velocity = 6.36943 m/sParameters
Returns
Interactive Calculator
Computing…
Set a range above first to export a graph.
FUNCTION
velocity_ins
This function returns the instantaneous velocity of a moving object at a certain moment of time t, given a function x which determines the position of the object at any moment of time. It is based on the fact that the instantaneous velocity function is given by the derivative of the position function
with respect to time, i.e.
Since this function uses numerical differentiation to compute the above derivative, an optional parameter eps is available to specify the precision of numerical computations.
Example 1
#include <codecogs/physics/kinematics/velocity.h>
#include <iostream>
// function defining the position at any moment of time t;
// in this case pos(t) = t^3
double pos(double t)
{
return t*t*t;
}
int main()
{
// time at which to calculate instantaneous velocity
double t = 11.43;
std::cout << std::endl;
std::cout << "Position = " << pos(t);
std::cout << " m" << std::endl;
std::cout << " Time = " << t;
std::cout << " s" << std::endl;
std::cout << std::endl;
// display instantaneous velocity at time t
std::cout << "Instantaneous velocity = " <<
Physics::Kinematics::velocity_ins(space, t);
std::cout << " m/s" << std::endl;
return 0;
}Output
Position = 1493.27 m
Time = 11.43 s
Instantaneous velocity = 391.935 m/sParameters
Returns
FUNCTION
velocity_ins
This function is based on the same equation as the previous one, only that it is able to compute the instantaneous velocities at several moments of time and return the results in the form of an array.
Notice the example code below which shows exactly how this is a generalisation of the previous overloaded function.
Example 1
#include <codecogs/physics/kinematics/velocity.h>
#include <iostream>
// function defining the position at any moment of time t;
// in this case pos(t) = t^3
double pos(double t)
{
return t*t*t;
}
int main()
{
// moments of time at which to evaluate
// the instantaneous velocity of the object
double t[10] = {
11.40, 11.41, 11.42, 11.43, 11.44,
11.45, 11.46, 11.47, 11.48, 11.49
};
// compute the instantaneous velocities
std::vector<double> time(t, t+10),
velocities = Physics::Kinematics::velocity_ins(distance, time);
// display the time, the position
// and the instantaneous velocities
std::cout << std::endl;
for (int i = 0; i < 10; i++)
{
std::cout << "Time = " << time[i] << " s";
std::cout << "\tPosition = " << pos(time[i]) << " m";
std::cout << "\tVelocity = " << velocities[i] << " m/s";
std::cout << std::endl;
}
return 0;
}Output
Time = 11.4 s Position = 1481.54 m Velocity = 389.88 m/s
Time = 11.41 s Position = 1485.45 m Velocity = 390.564 m/s
Time = 11.42 s Position = 1489.36 m Velocity = 391.249 m/s
Time = 11.43 s Position = 1493.27 m Velocity = 391.935 m/s
Time = 11.44 s Position = 1497.19 m Velocity = 392.621 m/s
Time = 11.45 s Position = 1501.12 m Velocity = 393.307 m/s
Time = 11.46 s Position = 1505.06 m Velocity = 393.995 m/s
Time = 11.47 s Position = 1509 m Velocity = 394.683 m/s
Time = 11.48 s Position = 1512.95 m Velocity = 395.371 m/s
Time = 11.49 s Position = 1516.91 m Velocity = 396.06 m/s