I have forgotten

• https://me.yahoo.com

# velocity

Average and instantaneous velocity of an object
Controller: CodeCogs

Private project under development, to help contact the author:

C++
Excel

## Overview

This module computes the average and instantaneous velocity of a moving object at given moments of time.

### Authors

Lucian Bentea (July 2007)

## Velocity Avg

 doublevelocity_avg( double xf double tf double x0 = 0 double t0 = 0 )[inline]
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/s

### Parameters

 xf final position on the axis (meters) tf final time (seconds) [needs to be different from t0] x0 Default value = 0 t0 Default value = 0

### Returns

the average velocity of the moving object (meters per second)
##### Source Code

This module is private, for owner's use only.

Not a member, then Register with CodeCogs. Already a Member, then Login.

## Velocity Ins

 doublevelocity_ins( double (*x)(double)[function pointer] double t double eps = 1E-6 )[inline]
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 2

#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/s

### Parameters

 x function defining the position of the object at any moment of time (meters) t the moment of time at which the instantaneous velocity is to be evaluated (seconds) eps Default value = 1E-6

### Returns

the instantaneous velocity of the object at time t (meters per second)
##### Source Code

This module is private, for owner's use only.

Not a member, then Register with CodeCogs. Already a Member, then Login.

## Velocity Ins

 std::vectorvelocity_ins( double (*x)(double)[function pointer] std::vector& t double eps = 1E-6 )[inline]
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 3

#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

### Parameters

 x function defining the position of the object at any moment of time (meters) t array containing the moments of time at which the instantaneous velocities should be evaluated (seconds) eps Default value = 1E-6

### Returns

array containing the instantaneous velocities of the object at moments of time given by t (meters per second)
##### Source Code

This module is private, for owner's use only.

Not a member, then Register with CodeCogs. Already a Member, then Login.