[工程师阿伟]正在和[机器小伟]一起研究[时间简史 爱因斯坦的相对论]。
<span style="font-size:18px;">#洛仑兹变换
def LTransfer(velocity, choice, pos = [0, 0, 0, 0]):
#[x, y, z, t] -> [x', y', z', t']
#
lightVelocity = 3e8;
c = lightVelocity;
v = velocity;
beta = v/c;
gamma = 1/(1-beta**2)**0.5;
if (choice == 1):
#从[x, y, z, t] -> [x', y', z', t']
x, y, z, t = pos[0], pos[1], pos[2], pos[3];
x_ = gamma*(x-v*t);
y_ = y;
z_ = z;
t_ = gamma*(t - v*x/c**2);
result = [x_, y_, z_, t_];
else:
#从[x, y, z, t] <- [x', y', z', t']
x_, y_, z_, t_ = pos[0], pos[1], pos[2], pos[3];
x = gamma*(x_ + v*t_);
y = y_;
z = z_;
t = gamma*(t_ + v*x_/c**2);
result = [x, y, z, t];
print('{0} 经过洛仑兹变换后是 {1}'.format(pos, result));
>>>
[0, 0, 0, 100] 经过洛仑兹变换后是 [-3015113445.7776365, 0, 0, 100.50378152592121]
def timeExpand(t, v):
c = 3e8;
gamma = 1/(1-(v/c)**2)**0.5;
t_ = gamma * t;
print('时间{0:.2e} 在速度 {1:.2e}下会膨胀成时间{2:.9e}'.format(t, v, t_));
def tmp():
#LTransfer(3e7, 1, [0, 0, 0, 100]);
for i in range(9):
timeExpand(1e9, 10**i);
for i in range(1, 20):
timeExpand(1e9, 1e8+ 1e7*i);
时间1.00e+09 在速度 1.00e+00下会膨胀成时间1.000000000e+09
时间1.00e+09 在速度 1.00e+01下会膨胀成时间1.000000000e+09
时间1.00e+09 在速度 1.00e+02下会膨胀成时间1.000000000e+09
时间1.00e+09 在速度 1.00e+03下会膨胀成时间1.000000000e+09
时间1.00e+09 在速度 1.00e+04下会膨胀成时间1.000000001e+09
时间1.00e+09 在速度 1.00e+05下会膨胀成时间1.000000056e+09
时间1.00e+09 在速度 1.00e+06下会膨胀成时间1.000005556e+09
时间1.00e+09 在速度 1.00e+07下会膨胀成时间1.000556019e+09
时间1.00e+09 在速度 1.00e+08下会膨胀成时间1.060660172e+09
时间1.00e+09 在速度 1.10e+08下会膨胀成时间1.074861546e+09
时间1.00e+09 在速度 1.20e+08下会膨胀成时间1.091089451e+09
时间1.00e+09 在速度 1.30e+08下会膨胀成时间1.109590082e+09
时间1.00e+09 在速度 1.40e+08下会膨胀成时间1.130667542e+09
时间1.00e+09 在速度 1.50e+08下会膨胀成时间1.154700538e+09
时间1.00e+09 在速度 1.60e+08下会膨胀成时间1.182165609e+09
时间1.00e+09 在速度 1.70e+08下会膨胀成时间1.213670091e+09
时间1.00e+09 在速度 1.80e+08下会膨胀成时间1.250000000e+09
时间1.00e+09 在速度 1.90e+08下会膨胀成时间1.292191477e+09
时间1.00e+09 在速度 2.00e+08下会膨胀成时间1.341640786e+09
时间1.00e+09 在速度 2.10e+08下会膨胀成时间1.400280084e+09
时间1.00e+09 在速度 2.20e+08下会膨胀成时间1.470871014e+09
时间1.00e+09 在速度 2.30e+08下会膨胀成时间1.557522395e+09
时间1.00e+09 在速度 2.40e+08下会膨胀成时间1.666666667e+09
时间1.00e+09 在速度 2.50e+08下会膨胀成时间1.809068067e+09
时间1.00e+09 在速度 2.60e+08下会膨胀成时间2.004459314e+09
时间1.00e+09 在速度 2.70e+08下会膨胀成时间2.294157339e+09
时间1.00e+09 在速度 2.80e+08下会膨胀成时间2.785430073e+09
时间1.00e+09 在速度 2.90e+08下会膨胀成时间3.905667329e+09</span>本节到此结束,欲知后事如何,请看下回分解。
原文:http://blog.csdn.net/mwsister/article/details/51882400