Physics › Kinematics ›
velocity
Average and instantaneous velocity of an object
Controller: CodeCogs
Dependents
Interface
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] |
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; }
OutputFinal 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] |
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; }
OutputPosition = 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::vector<double>velocity_ins( | double | (*x)(double)[function pointer] | |
std::vector<double>& | t | ||
double | eps = 1E-6 | )[inline] |
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; }
OutputTime = 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.