// calculates the velocity required and earth time passed to travel to a distant // place at relativistic speeds with some moving reference frame travel time. // e.g. if it takes you 3 years travel time to travel 50lyr, what is your velocity // and how much earth time has passed before you get there. #include #include #include #include using namespace std; double travelTime, Distance, velocity, earthTime; double tol = 0.0000001; double func(double v) { return (Distance / v) - (travelTime / sqrt(1-pow(v,2.0))); //setting c = 1 } double deriv(double v) { return (-Distance / pow(v,2.0)) + (0.5*travelTime / pow(1-pow(v,2.0),1.5))*(-2.0*v); } int main() { cout << "Travel Time (years) = "; cin >> travelTime; cout << "Distance (light-years) = "; cin >> Distance; velocity = 0.9; //initial guess int i = 1000000.0; //maximum iterations after which assume v = c do //NR Method { velocity -= func(velocity) / deriv(velocity); if (velocity >= 1.0){velocity = 1.0-tol;} i -= 1.0; } while ((fabs(func(velocity)) >= tol) and (i > 0)); if (i==0) { earthTime = Distance; } else if (velocity < 0) { velocity = 0; earthTime = travelTime; } else { earthTime = (travelTime / sqrt(1-pow(velocity,2.0))); } cout << "Velocity = " << velocity << " c" << endl; cout << "Earth Time = " << earthTime << " years" << endl; return 0; }